private void UpdateNavigationContext(IOperationCallback callback, IViewModel navigationViewModel, NavigationEventArgsBase args, ref INavigationContext context)
        {
            var vmType = context.GetData(ViewModelType);

            if (vmType == null)
            {
                return;
            }

            var viewModel = GetViewModelForView(args, navigationViewModel, context, vmType);

            if (!ReferenceEquals(context.ViewModelTo, viewModel))
            {
                context = new NavigationContext(context.NavigationMode, context.ViewModelFrom, viewModel,
                                                context.NavigationProvider, context.Parameters);
            }
            if (viewModel != null && callback != null)
            {
                RegisterOperationCallback(viewModel, callback, context);
            }
        }
Пример #2
0
        private void OnSelectedItemChangedInternal(IViewModel oldValue, IViewModel newValue)
        {
            ISelectable selectable;
            INavigableViewModel navigableViewModel;
            NavigationContext ctx = null;
            if (ItemsSource.Contains(oldValue))
            {
                selectable = oldValue as ISelectable;
                if (selectable != null)
                    selectable.IsSelected = false;

                navigableViewModel = oldValue as INavigableViewModel;
                if (navigableViewModel != null)
                {
                    ctx = new NavigationContext(NavigationType.Tab, NavigationMode.Refresh, oldValue, newValue, this);
                    navigableViewModel.OnNavigatedFrom(ctx);
                }
            }

            selectable = newValue as ISelectable;
            if (selectable != null)
                selectable.IsSelected = true;
            navigableViewModel = newValue as INavigableViewModel;
            if (navigableViewModel != null)
                navigableViewModel.OnNavigatedTo(ctx ??
                                                 new NavigationContext(NavigationType.Tab, NavigationMode.Refresh, oldValue, newValue, this));

            OnSelectedItemChanged(oldValue, newValue);
            if (SelectedItemChanged == null)
                return;
            var args = new SelectedItemChangedEventArgs<IViewModel>(oldValue, newValue);
            ThreadManager.Invoke(Settings.EventExecutionMode, this, args, (model, eventArgs) =>
            {
                model.SelectedItemChanged?.Invoke(model, eventArgs);
            });
        }
 protected virtual void MultiViewModelOnViewModelClosed(object sender, ValueEventArgs<IViewModel> args)
 {
     var context = new NavigationContext(NavigationType.Tab, NavigationMode.Back, args.Value,
         MultiViewModel.SelectedItem, MultiViewModel);
     bool? result = null;
     var hasOperationResult = args.Value as IHasOperationResult;
     if (hasOperationResult != null)
         result = hasOperationResult.OperationResult;
     CallbackManager.SetResult(args.Value, OperationResult.CreateResult(OperationType.TabNavigation, args.Value, result, context));
 }
 private void ClearCacheIfNeed(IDataContext context, IViewModel viewModelTo)
 {
     if (!context.GetData(ClearNavigationCache) || CachePolicy == null)
         return;
     var viewModels = CachePolicy.Invalidate(context);
     foreach (var viewModelFrom in viewModels.Reverse())
     {
         var navigationContext = new NavigationContext(NavigationType.Page, NavigationMode.Reset, viewModelFrom, viewModelTo, this);
         if (!OnViewModelClosed(viewModelFrom, navigationContext, this, true))
             CompleteOperationCallback(viewModelFrom, navigationContext);
     }
 }
        private void UpdateNavigationContext(IOperationCallback callback, IViewModel navigationViewModel, NavigationEventArgsBase args, ref INavigationContext context)
        {
            var vmType = context.GetData(ViewModelTypeConstant);
            if (vmType == null)
                return;

            var viewModel = GetViewModelForView(args, navigationViewModel, context, vmType);
            if (!ReferenceEquals(context.ViewModelTo, viewModel))
                context = new NavigationContext(NavigationType.Page, context.NavigationMode, context.ViewModelFrom, viewModel, context.NavigationProvider);
            if (viewModel != null && callback != null)
                RegisterOperationCallback(viewModel, callback, context);
        }
 /// <summary>
 ///     Raised after the view model navigation.
 /// </summary>
 /// <param name="viewModel">The specified view model.</param>
 /// <param name="mode">The specified navigation mode.</param>
 /// <param name="context">The specified <see cref="IDataContext" />.</param>
 public virtual void OnNavigated(IViewModel viewModel, NavigationMode mode, IDataContext context)
 {
     Should.NotBeNull(viewModel, "viewModel");
     var navigationContext = new NavigationContext(NavigationType.Page, mode, CurrentViewModel, viewModel, this);
     var currentViewModel = CurrentViewModel;
     if (currentViewModel != null)
         TryCacheViewModel(navigationContext, CurrentContent ?? currentViewModel.Settings.Metadata.GetData(ViewModelConstants.View), currentViewModel);
     OnNavigated(navigationContext);
 }
 protected virtual void MultiViewModelOnViewModelClosed(object sender, ValueEventArgs<IViewModel> args)
 {
     var context = new NavigationContext(NavigationType.Tab, NavigationMode.Back, args.Value,
         MultiViewModel.SelectedItem, MultiViewModel);
     var result = ViewModelExtensions.GetOperationResult(args.Value);
     CallbackManager.SetResult(OperationResult.CreateResult(OperationType.TabNavigation, args.Value, result, context));
 }