SlideShare a Scribd company logo
Navigation


  Eyal Vardi
  CEO E4D Solutions LTD
  Microsoft MVP Visual C#
  blog: www.eVardi.com
Agenda
           Interaction Request

           State-Based Navigation

           View-Based Navigation




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Interaction Request




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
View Model Codes Sample
        InteractionRequest<Confirmation> action { get; set; }

        action.Raise(
             new Confirmation { Title = "Test II", Content = DateTime.Now },
             x => Date = x.Content.ToString()
        );




        <ei:Interaction.Triggers>
           <prism:InteractionRequestTrigger
               SourceObject="{Binding action}">
               <prism:PopupChildWindowAction
                        ContentTemplate="{StaticResource NT}"/>
        </ei:Interaction.Triggers>




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Interaction in ViewModel




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Interaction in View




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Interaction Request


© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
State-Based Navigation




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
State-Based Navigation


                                                                                 View
                                                           Binding
                                                                                 Model




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
State-Based Navigation




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Data State Behavior
        <i:Interaction.Behaviors>
             <ei:DataStateBehavior Binding="{Binding ShowDetails}" Value="True"
                     TrueState="ShowDetails"
                     FalseState="ShowContacts"/>
        </i:Interaction.Behaviors>

        <VisualStateManager.VisualStateGroups>

             <VisualStateGroup x:Name="DetailStates">

                    <VisualStateGroup.Transitions />

                    <VisualState x:Name="ShowContacts" />
                    <VisualState x:Name="ShowContacts" />

             </VisualStateGroup>

        </VisualStateManager.VisualStateGroups>




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Data State Behavior


© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
View-Based Navigation




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Basic Region Navigation
           The view to be displayed is identified via a URI
                regionManager.RequestNavigate(
                                "MainRegion",
                                new Uri("InboxView", UriKind.Relative) );




           View Registration
                // Unity
                container.RegisterType<object, InboxView>("InboxView");

                // MEF
                [Export("InboxView")]
                public partial class InboxView : UserControl




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
RequestNavigate Method
           The RequestNavigate method also allows you
            to specify a callback method, or a delegate,
            which will be called when navigation is
            complete.

        private void SelectedEmployeeChanged(object sender, EventArgs e)
        {
           ...
           regionManager.RequestNavigate(
             RegionNames.TabRegion, "EmployeeDetails", NavigationCompleted);
        }

        private void NavigationCompleted(NavigationResult result) { ... }




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
INavigationAware Interface
           By implementing this interface, your view or
            view model can opt-in to participate in the
            navigation process.

        public interface INavigationAware
        {
           bool IsNavigationTarget( NavigationContext navigationContext );
           void OnNavigatedTo     ( NavigationContext navigationContext );
           void OnNavigatedFrom   ( NavigationContext navigationContext );
        }




                                                                      IsNavigationTarget
            View I                                                                           View II
             ( Form )           OnNavigatedFrom                              OnNavigatedTo    ( To )

© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Basic Navigation


© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
IRegionMemberLifetime
           Sometimes you will want the deactivated view
            to be removed from the region.


        public class EmployeeDetailsViewModel : IRegionMemberLifetime
        {
           public bool KeepAlive { get { return true; } }
        }




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Passing Parameters During
   Navigation
        Employee employee = Employees.CurrentItem as Employee;

        if (employee != null)
        {
           UriQuery query = new UriQuery();
           query.Add("ID", employee.Id);

             _regionManager.RequestNavigate( RegionNames.TabRegion,
                        new Uri("EmployeeDetailsView" + query.ToString(),
                        UriKind.Relative) );
        }



        public void OnNavigatedTo( NavigationContext navigationContext )
        {
           string id = navigationContext.Parameters["ID"];
        }


© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
IRegionNavigationContentLoader




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Confirming or Cancelling Nav




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
IConfirmNavigationRequest
           The implementation of this method invokes
            the interaction request defined earlier so that
            the user can confirm or cancel the navigation
            operation.

        void IConfirmNavigationRequest.ConfirmNavigationRequest(
                           NavigationContext navContext, Action<bool> callback)
        {
           this.confirmExitInteractionRequest.Raise (
               new Confirmation { Content = "...", Title = "..." },
               c => callback(c.Confirmed)
           );
        }




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Confirming or Cancelling
     Navigation

© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Using the Navigation Journal
           The NavigationContext class provides access
            to the region navigation service.
           The region navigation service implements the
            IRegionNavigationService.

        public interface IRegionNavigationService : INavigateAsync
        {
          IRegion Region {get; set;}
          IRegionNavigationJournal Journal {get;}
          event EventHandler<RegionNavigationEventArgs> Navigating;
          event EventHandler<RegionNavigationEventArgs> Navigated;
          event EventHandler<RegionNavigationFailedEventArgs> NavigationFailed;
        }




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
IRegionNavigationJournal
           The Journal property provides access to the
            navigation journal associated with the region.

        public interface IRegionNavigationJournal
        {
           bool CanGoBack { get; }
           bool CanGoForward { get; }
           IRegionNavigationJournalEntry CurrentEntry { get; }
           INavigateAsync NavigationTarget { get; set; }
           void Clear();
           void GoBack();
           void GoForward();
           void RecordNavigation(IRegionNavigationJournalEntry entry);
        }




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
The Region
   Navigation
   Sequence




© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
Navigation


© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il

More Related Content

Prism Navigation

  • 1. Navigation Eyal Vardi CEO E4D Solutions LTD Microsoft MVP Visual C# blog: www.eVardi.com
  • 2. Agenda  Interaction Request  State-Based Navigation  View-Based Navigation © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 3. Interaction Request © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 4. View Model Codes Sample InteractionRequest<Confirmation> action { get; set; } action.Raise( new Confirmation { Title = "Test II", Content = DateTime.Now }, x => Date = x.Content.ToString() ); <ei:Interaction.Triggers> <prism:InteractionRequestTrigger SourceObject="{Binding action}"> <prism:PopupChildWindowAction ContentTemplate="{StaticResource NT}"/> </ei:Interaction.Triggers> © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 5. Interaction in ViewModel © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 6. Interaction in View © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 7. Interaction Request © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 8. State-Based Navigation © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 9. State-Based Navigation View Binding Model © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 10. State-Based Navigation © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 11. Data State Behavior <i:Interaction.Behaviors> <ei:DataStateBehavior Binding="{Binding ShowDetails}" Value="True" TrueState="ShowDetails" FalseState="ShowContacts"/> </i:Interaction.Behaviors> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="DetailStates"> <VisualStateGroup.Transitions /> <VisualState x:Name="ShowContacts" /> <VisualState x:Name="ShowContacts" /> </VisualStateGroup> </VisualStateManager.VisualStateGroups> © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 12. Data State Behavior © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 13. View-Based Navigation © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 14. Basic Region Navigation  The view to be displayed is identified via a URI regionManager.RequestNavigate( "MainRegion", new Uri("InboxView", UriKind.Relative) );  View Registration // Unity container.RegisterType<object, InboxView>("InboxView"); // MEF [Export("InboxView")] public partial class InboxView : UserControl © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 15. RequestNavigate Method  The RequestNavigate method also allows you to specify a callback method, or a delegate, which will be called when navigation is complete. private void SelectedEmployeeChanged(object sender, EventArgs e) { ... regionManager.RequestNavigate( RegionNames.TabRegion, "EmployeeDetails", NavigationCompleted); } private void NavigationCompleted(NavigationResult result) { ... } © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 16. INavigationAware Interface  By implementing this interface, your view or view model can opt-in to participate in the navigation process. public interface INavigationAware { bool IsNavigationTarget( NavigationContext navigationContext ); void OnNavigatedTo ( NavigationContext navigationContext ); void OnNavigatedFrom ( NavigationContext navigationContext ); } IsNavigationTarget View I View II ( Form ) OnNavigatedFrom OnNavigatedTo ( To ) © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 17. Basic Navigation © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 18. IRegionMemberLifetime  Sometimes you will want the deactivated view to be removed from the region. public class EmployeeDetailsViewModel : IRegionMemberLifetime { public bool KeepAlive { get { return true; } } } © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 19. Passing Parameters During Navigation Employee employee = Employees.CurrentItem as Employee; if (employee != null) { UriQuery query = new UriQuery(); query.Add("ID", employee.Id); _regionManager.RequestNavigate( RegionNames.TabRegion, new Uri("EmployeeDetailsView" + query.ToString(), UriKind.Relative) ); } public void OnNavigatedTo( NavigationContext navigationContext ) { string id = navigationContext.Parameters["ID"]; } © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 20. IRegionNavigationContentLoader © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 21. Confirming or Cancelling Nav © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 22. IConfirmNavigationRequest  The implementation of this method invokes the interaction request defined earlier so that the user can confirm or cancel the navigation operation. void IConfirmNavigationRequest.ConfirmNavigationRequest( NavigationContext navContext, Action<bool> callback) { this.confirmExitInteractionRequest.Raise ( new Confirmation { Content = "...", Title = "..." }, c => callback(c.Confirmed) ); } © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 23. Confirming or Cancelling Navigation © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 24. Using the Navigation Journal  The NavigationContext class provides access to the region navigation service.  The region navigation service implements the IRegionNavigationService. public interface IRegionNavigationService : INavigateAsync { IRegion Region {get; set;} IRegionNavigationJournal Journal {get;} event EventHandler<RegionNavigationEventArgs> Navigating; event EventHandler<RegionNavigationEventArgs> Navigated; event EventHandler<RegionNavigationFailedEventArgs> NavigationFailed; } © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 25. IRegionNavigationJournal  The Journal property provides access to the navigation journal associated with the region. public interface IRegionNavigationJournal { bool CanGoBack { get; } bool CanGoForward { get; } IRegionNavigationJournalEntry CurrentEntry { get; } INavigateAsync NavigationTarget { get; set; } void Clear(); void GoBack(); void GoForward(); void RecordNavigation(IRegionNavigationJournalEntry entry); } © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 26. The Region Navigation Sequence © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 27. Navigation © 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il