Ejemplo n.º 1
0
        /// <summary>
        /// Handles the Navigated event.
        /// </summary>
        /// <param name="viewModelToBind">ViewModel to be bound to the target view or null</param>
        private void SubscribeNavigatedHandler(NavigableViewModelBase viewModelToBind)
        {
            NavigatedEventHandler navigatedHandler = null;

            navigatedHandler = (sender, e) =>
            {
                _frame.Navigated -= navigatedHandler;
                HandleServiceNavigatedToContent(e, viewModelToBind);
            };

            _frame.Navigated += navigatedHandler;
        }
Ejemplo n.º 2
0
        private void HandleServiceNavigatedToContent(NavigationEventArgs e, NavigableViewModelBase viewModelToBind)
        {
            _navigableViewModel.RaiseNavigatedFrom(e);

            // Raise navigated to viewmodel event if the target view defines navigable view model
            FrameworkElement element = e.Content as FrameworkElement;

            if (element != null)
            {
                RoutedEventHandler elementLoadedHandler = null;
                elementLoadedHandler = delegate
                {
                    element.Loaded -= elementLoadedHandler;

                    if (viewModelToBind != null)
                    {
                        element.DataContext = viewModelToBind;
                    }

                    // Enable navigation for the viewmodel


                    // Raise navigated to
                    NavigableViewModelBase navigableViewModel = element.DataContext as NavigableViewModelBase;                     // ViewModel may be sent by the view and viewModelToBind == true
                    if (navigableViewModel != null)
                    {
                        NavigationServiceFrame navigationService = new NavigationServiceFrame(navigableViewModel, _frame);
                        navigableViewModel.EnableNavigation(navigationService);

                        navigableViewModel.RaiseNavigatedTo(e);
                    }
                };

                element.Loaded += elementLoadedHandler;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NavigationServiceFrame"/> class.
 /// </summary>
 /// <param name="navigableViewModel">The navigator view model.</param>
 /// <param name="frame">The navigation service.</param>
 internal NavigationServiceFrame(NavigableViewModelBase navigableViewModel, Frame frame)
 {
     _navigableViewModel = navigableViewModel;
     _frame = frame;
 }