I have a MasterDetail page. The Detail is a NavigationPage. In the NavigationPage I put a ContentPage. So the hierarchy is:
MasterDetail
- Master
- Detail
- NavigationPage
- ContentPage
The navigation bar in my NavigationPage has an ActivityIndicator in it. The IsRunning property of the ActivityIndicator is bound to the IsRunning property of my ContentPage's view model. So when I load the ContentPage I see a spinning ActivityIndicator in the navigation bar. This works fine.
When I navigate to a new page, I call PushAsync on the NavigationPage to push a new ContentPage on the stack. The new page I push also has a view model with an IsRunning property. The problem is that the binding in the navigation bar is now broken and never shows the ActivityIndicator as running even if I set IsRunning to true.
So it feels like the binding gets broken on navigation. Any ideas on the root cause or how to fix this? Thanks in advance!
Mistake on my end, I wasn't calling SetTitleView when the new ContentPage was loaded. Turned out it wasn't a binding issue.
Related
I'm developing application, where I have to dynamicaly create/delete tabs in TabbedPage.
Let say that I have workout with excercises, each excercise has to have own page. When I'm passing workoutViewModel by contructor I can create tabs in code behind, rest code I have in viewModel. User can add or remove some excercise this cause that tabs have to change.
How can I manage tabs in tabbedPage from ViewModel? This ViewModel is BindingContext in this page.
How can I manage tabs in tabbedPage from ViewModel? This ViewModel is BindingContext in this page.
If you want to display tab in Tabbedpage with ViewModel, I think you can assign a DataTemplate to the ItemTemplate property to return pages for objects in the collection.
Like this sample:
https://github.com/xamarin/xamarin-forms-samples/tree/master/Navigation/TabbedPage
I need a simulated behavior as if a Tabbed Page button is clicked from the Content Page. This button is in the ContentView.
Thanks.
You may crate an event at ContentPage like:
public delegate void BtnClickDelegate(string parameter);
public event BtnClickDelegate TriggerEvent;
Then Subscribe this event in your TabbedPage: pageOne.TriggerEvent += PageOne_TriggerEvent;
When you trigger your event in the page TriggerEvent(string ...), method in TabbedPage will fire.
In Tabbed page sample given by Prism, I want to navigate from ViewA (first tab) to ViewD(not the next tab but next navigation page).
I don't understand why this removes the navigation bar on the top:
_navigationService.NavigateAsync(nameof(ViewD));
Like PushModelAsync instead of PushAsync. So that I loose the back button on the navigation tab which is not intended.
Am I missing something here?
The reason for this is that ViewA’s parent is not a NavigationPage, the result is that the Navigation Service assumes you want modal Navigation. You simply need to add useModalNavigation: false, this will make the Navigation Service push ViewD correctly inside the Navigation Page.
In my root view model I call something like
await _navigationService.NavigateAsync(
"/NavigationPage/Page1of2",
useModalNavigation: true
);
Sure enough it loads both view models in a modal navigation just fine. In Page1of2ViewModel I do another
await _navigationService.NavigateAsync(
"Page2of2",
useModalNavigation: false
);
Which view model now should dismiss that modal and how?
Using GoBackAsync() or GoBackAsync(useModalNavigation: true) neither of the 3 view model seem to be able to dismiss the modal flow back to my root view model.
When you place a "/" in you are signifying an absolute navigation. This is resetting the navigation stack completely. It's the same as MainPage = new MyPage(). So there is no modal navigation occurring here. The only way to pop a page off the stack is to use the NavigationService.GoBackAsync, or use the built-in software/hardware buttons to go back.
So I tried everything with showing up the back button but it just won't work
This is how i arrange my View Controllers Used segue show from view controller to site view controller
And here is the site view controller that isn't showing back button
I even tried adding NavigationBar and a button with this function
self.navigationController.popToRootViewControllerAnimated(true)
Also failed
Update:
I tried this in both view controllers it's returning nil
in viewDidAppear and viewWillAppear
print(self.navigationController?.restorationIdentifier)
Once I got the same problem, when I was try to use view property of my UIViewController before it loaded properly. This caused problems with loading my navigation bar items. In fact, you should not touch view property until viewDidLoad method is called. Check, maybe it is your case, maybe you use view property in prepareForSegue method or in observers?