Created
August 3, 2016 22:03
-
-
Save dansiegel/cdc81671f3610d8992d70c65c202f0a4 to your computer and use it in GitHub Desktop.
Prism Tabbed Navigation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BehaviorBase<T> : Behavior<T> where T : BindableObject | |
{ | |
public T AssociatedObject { get; private set; } | |
protected override void OnAttachedTo( T bindable ) | |
{ | |
base.OnAttachedTo( bindable ); | |
AssociatedObject = bindable; | |
if( bindable.BindingContext != null ) | |
{ | |
BindingContext = bindable.BindingContext; | |
} | |
bindable.BindingContextChanged += OnBindingContextChanged; | |
} | |
protected override void OnDetachingFrom( T bindable ) | |
{ | |
base.OnDetachingFrom( bindable ); | |
bindable.BindingContextChanged -= OnBindingContextChanged; | |
AssociatedObject = null; | |
} | |
void OnBindingContextChanged( object sender, EventArgs e ) | |
{ | |
OnBindingContextChanged(); | |
} | |
protected override void OnBindingContextChanged() | |
{ | |
base.OnBindingContextChanged(); | |
BindingContext = AssociatedObject.BindingContext; | |
} | |
} |
This doesn't handle passing NavigationParameters from the MultiPage (TabbedPage) to the Children. If you feel there is a need for that please update the Prism issue and I'll see what we can do.
Thank you so much for this! I changed it to use IActiveAware
instead since I'm used to that with WPF. I don't need any parameters passed at this time, but if I do I may end up switching back to this.
Could you share how you implemented it @JoshClose? please. I'm trying to implement the IActiveAware without success.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How would you get the navigation parameters from the the multipage to the content page?Update: Nevermind, just put values from the previous page into the parameters when they are passed to
OnNavigateFrom