Issue
I have a problem/question?
I created a button in my custom navigation menu, so when I click the button it goes to for example Page1. But now I only want to make the button active if the current active page not is equal to Page1. Is this possible and how?
Solution
If I understand correctly, you want to disable the button when Page1 is being displayed.
Most, if not all, Xamarin Forms controls have an IsEnabled
property, so you want to set this to false
when Page1
appears, and to true
when it disappears. A ContentPage
has onAppearing
and OnDisappearing
virtual methods that you can override to run code when the page appears and disappears respectively.
However, context matters. Knowing absolutely nothing about how you have set up your custom navigation menu, I cannot say exactly how you can do this. Is a reference to the button available in the ContentPage
's OnAppearing
method? If not, you need some way to get a reference to the button, or if the button is using bindings, to the view model that the button is binding to (which assumes you are using a binding for the IsEnabled
property of the button), to set the appropriate property to disable/enable the button.
EDIT: Oh and see your actual question was if you can see the current active page. You can check Application.Current.MainPage
to see what page is currently active, but if it is a NavigationPage
, then you would have to retrieve the last page in the navigation stack to see what page is actually being displayed. Likewise for any other "container" page, like a TabbedPage
, you would have to see what page the container page is actually displaying. For a TabbedPage
you would have to check the currently selected tab and get the page that is being displayed there, and then if this is a NavigationPage
the you have to, again, check the stack for the last page.
Answered By - jgoldberger - MSFT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.