public NavigatedEventArgs([NotNull] INavigationContext context, bool isCanceled, [CanBeNull] Exception exception)
 {
     Should.NotBeNull(context, nameof(context));
     _context   = context;
     IsCanceled = isCanceled;
     Exception  = exception;
 }
Example #2
0
 public override async void OnNavigatedTo(INavigationContext context)
 {
     if (!context.Attribute.IsRestore())
     {
         await Navigator.PostActionAsync(() => BusyState.Using(InitializeAsync));
     }
 }
        public void SetNavigationContext(INavigationContext navigationContext)
        {
            if (navigationContext == null)
                throw new ArgumentNullException(nameof(navigationContext));

            _navigationContext = navigationContext;
        }
Example #4
0
        private void CompleteClose()
        {
            INavigationContext context = CreateCloseContext();

            OnClosed(_closeParameter, context);

            bool?result          = null;
            var  operationResult = ViewModel as IHasOperationResult;

            if (operationResult != null)
            {
                result = operationResult.OperationResult;
            }
            OperationCallbackManager.SetResult(ViewModel,
                                               OperationResult.CreateResult(OperationType.WindowNavigation, ViewModel, result, context));

            _closeParameter = null;
            _shouldClose    = false;
            _isOpen         = false;
            TView view = View;

            if (view == null)
            {
                return;
            }
            ThreadManager.InvokeOnUiThreadAsync(() =>
            {
                CleanupView(view);
                _viewManager
                .CleanupViewAsync(ViewModel)
                .WithTaskExceptionHandler(ViewModel);
            });
            View = null;
        }
Example #5
0
 public Task <bool> OnNavigatingFrom(INavigationContext context)
 {
     return(_messagePresenter
            .ShowAsync("Close SecondViewModel?", string.Empty, MessageButton.YesNo,
                       MessageImage.Question)
            .TryExecuteSynchronously(task => task.Result == MessageResult.Yes));
 }
        public virtual IViewModel TryTakeViewModelFromCache(INavigationContext context, object view)
        {
            view = ToolkitExtensions.GetUnderlyingView <object>(view);
            var type = view.GetType();
            List <IViewModel> list;

            if (!_cachedViewModels.TryGetValue(type, out list) || list == null || list.Count == 0)
            {
                if (Tracer.TraceInformation)
                {
                    Tracer.Info("Navigation cache - the view model for the view {0} is not found in the cache, navigation mode: {1}", type, context.NavigationMode);
                }
                return(null);
            }
            IViewModel vm = list[0];

            list.RemoveAt(0);
            if (list.Count == 0)
            {
                _cachedViewModels.Remove(type);
            }
            if (Tracer.TraceInformation)
            {
                Tracer.Info("Navigation cache - the view model {0} for the view {1} was taken from the cache, navigation mode: {2}",
                            vm.GetType(), type, context.NavigationMode);
            }
            return(vm);
        }
Example #7
0
    private static async Task <INode?> MovePreviousAsync(IBlock block, INavigationContext context, IBlockIterationState blockState)
    {
        await LeaveCurrentNodeAsync(blockState, context);

        var index = blockState.CurrentNodeIndex ?? (block.Nodes.Count - 1);

        for (; ;)
        {
            if (!blockState.BackwardStack.TryPop(out var state))
            {
                blockState.CurrentNodeIndex = null;
                blockState.CurrentNode      = null;
                return(null);
            }

            if (state is not BlockedNode)
            {
                var node = block.Nodes[index];

                blockState.CurrentNodeIndex = blockState.CurrentNodeIndex = index > 0 ? index - 1: null;
                blockState.CurrentNode      = node;

                await node.EnterAsync(context, state);

                return(node);
            }

            index--;
        }
    }
Example #8
0
    public async Task <INode?> MoveAsync(IBlock block, IBlockState blockState, INavigationContext context, bool forward)
    {
        context.State.CurrentBlockId = block.Id;

        for (; ;)
        {
            if (forward)
            {
                var node = await MoveNextAsync(block, context, blockState.GetCurrentIteration());

                if (node is not null || block.While is null || !block.While.Evaluate(context.Variables))
                {
                    return(node);
                }
                blockState.MoveToNextIteration();
            }
            else
            {
                var node = await MovePreviousAsync(block, context, blockState.GetCurrentIteration());

                if (node is not null || block.While is null || !blockState.MoveToPreviousIteration())
                {
                    return(node);
                }
            }
        }
    }
Example #9
0
        public void WhenSelectedItemChangedVmShouldCallOnNavigatedFrom_ToMethods()
        {
            ThreadManager.ImmediateInvokeOnUiThreadAsync = true;
            var viewModel1 = GetViewModel <NavigableViewModelMock>();
            var viewModel2 = GetViewModel <NavigableViewModelMock>();

            var multiViewModel = GetMultiViewModel();

            multiViewModel.AddViewModel(viewModel1);
            multiViewModel.AddViewModel(viewModel2);

            multiViewModel.SelectedItem = null;
            INavigationContext ctxTo1 = null, ctxFrom1 = null, ctxTo2 = null, ctxFrom2 = null;

            viewModel1.OnNavigatedFromDelegate = context => ctxFrom1 = context;
            viewModel1.OnNavigatedToDelegate   = context => ctxTo1 = context;
            viewModel2.OnNavigatedFromDelegate = context => ctxFrom2 = context;
            viewModel2.OnNavigatedToDelegate   = context => ctxTo2 = context;

            multiViewModel.SelectedItem = viewModel1;
            ctxTo1.NavigationMode.ShouldEqual(NavigationMode.Refresh);
            ctxTo2.ShouldBeNull();
            ctxFrom1.ShouldBeNull();
            ctxFrom2.ShouldBeNull();

            ctxTo1 = null;
            multiViewModel.SelectedItem = viewModel2;
            ctxFrom1.NavigationMode.ShouldEqual(NavigationMode.Refresh);
            ctxTo2.NavigationMode.ShouldEqual(NavigationMode.Refresh);
            ctxTo1.ShouldBeNull();
            ctxFrom2.ShouldBeNull();
        }
Example #10
0
        public Task Initialize(INavigationContext rootContext)
        {
            ClearNavigationHistory();
            _activeFrame = new NavigationFrame { Context = rootContext };

            return _activeFrame.Context.Activate();
        }
 private void Renavigate(IViewModel currentViewModel, INavigationContext context, NavigatingCancelEventArgsBase args)
 {
     if (CurrentContent != null)
     {
         TryCacheViewModel(context, CurrentContent, currentViewModel);
     }
     if (_navigatingCancelArgs == null)
     {
         if (args.IsCancelable && args.NavigationMode == NavigationMode.Back)
         {
             NavigationService.GoBack();
         }
         else
         {
             if (!NavigationService.Navigate(args))
             {
                 CancelCurrentNavigation(context);
             }
         }
     }
     else
     {
         _navigatingCancelArgs.Cancel = false;
     }
 }
Example #12
0
 /// <summary>
 ///     Menus the specified HTML.
 /// </summary>
 /// <param name="html">The HTML.</param>
 /// <param name="navigationContext">The navigation context.</param>
 /// <param name="itemContent">Content of the item.</param>
 /// <param name="selectedItemContent">Content of the selected item.</param>
 /// <param name="expandedItemContent">Content of the expanded item.</param>
 /// <param name="enableDisplayInMenu">if set to <c>true</c> [enable display in menu].</param>
 /// <returns></returns>
 public static MvcHtmlString Menu(this HtmlHelper html, INavigationContext navigationContext,
                                  Func <IPage, MvcHtmlString> itemContent, Func <IPage, MvcHtmlString> selectedItemContent,
                                  Func <IPage, MvcHtmlString> expandedItemContent, bool enableDisplayInMenu = true)
 {
     return(Menu(html, navigationContext, itemContent, selectedItemContent, expandedItemContent, null,
                 enableDisplayInMenu));
 }
Example #13
0
 public StoryboardTests()
 {
     sceneNavigator    = A.Fake <ISceneNavigator>(i => i.Strict());
     eventManager      = A.Fake <IEventManager>(i => i.Strict());
     navigationContext = A.Fake <INavigationContext>(i => i.Strict());
     sut = new Storyboard(navigationContext, sceneNavigator, eventManager);
 }
 private void TryCacheViewModel(INavigationContext context, object view, IViewModel viewModel)
 {
     if (CachePolicy != null && view != null && viewModel != null)
     {
         CachePolicy.TryCacheViewModel(context, view, viewModel);
     }
 }
        protected virtual Task <bool> OnNavigatingInternalAsync(INavigationContext context)
        {
            bool data;

            if (context.TryGetData(NavigationConstants.ImmediateClose, out data) && data)
            {
                return(Empty.TrueTask);
            }
            bool isClose        = context.NavigationMode.IsClose() && context.ViewModelFrom != null;
            var  navigatingTask = OnNavigatingFromAsync(context) ?? Empty.TrueTask;

            if (!isClose)
            {
                return(navigatingTask);
            }

            if (navigatingTask.IsCompleted)
            {
                if (navigatingTask.Result)
                {
                    return(OnClosingAsync(context.ViewModelFrom, context));
                }
                return(Empty.FalseTask);
            }
            return(navigatingTask
                   .TryExecuteSynchronously(task =>
            {
                if (task.Result)
                {
                    return OnClosingAsync(context.ViewModelFrom, context);
                }
                return Empty.FalseTask;
            }).Unwrap());
        }
 private static void Trace(string navigationName, INavigationContext context)
 {
     if (Tracer.TraceInformation)
     {
         Tracer.Info($"{navigationName}({context.NavigationMode}) from '{context.ViewModelFrom}' to '{context.ViewModelTo}', type '{context.NavigationType}'");
     }
 }
Example #17
0
 private static void NotifyActiveViewsNavigatingFrom(INavigationContext navigationContext, object[] activeViews)
 {
     foreach (var item in activeViews)
     {
         MvvmHelpers.OnNavigatedFrom(item, navigationContext);
     }
 }
 /// <summary>
 ///     Initializes the <see cref="NavigatedEventArgs" />.
 /// </summary>
 public NavigatedEventArgs([NotNull]INavigationContext context, [NotNull] IViewModel viewModel)
 {
     Should.NotBeNull(context, "context");
     Should.NotBeNull(viewModel, "viewModel");
     _context = context;
     _viewModel = viewModel;
 }
Example #19
0
        private void ExecuteNavigation(INavigationContext navigationContext, object[] activeViews, Action <IRegionNavigationResult> navigationCallback)
        {
            try
            {
                NotifyActiveViewsNavigatingFrom(navigationContext, activeViews);

                var view = (VisualElement)_regionNavigationContentLoader.LoadContent(Region, navigationContext);

                // Raise the navigating event just before activating the view.
                RaiseNavigating(navigationContext);

                Region.Activate(view);

                // Update the navigation journal before notifying others of navigation
                IRegionNavigationJournalEntry journalEntry = _container.Resolve <IRegionNavigationJournalEntry>();
                journalEntry.Uri        = navigationContext.Uri;
                journalEntry.Parameters = navigationContext.Parameters;

                bool persistInHistory = PersistInHistory(view);

                Journal.RecordNavigation(journalEntry, persistInHistory);

                // The view can be informed of navigation
                MvvmHelpers.OnNavigatedTo(view, navigationContext);

                navigationCallback(new RegionNavigationResult(navigationContext, true));

                // Raise the navigated event when navigation is completed.
                RaiseNavigated(navigationContext);
            }
            catch (Exception e)
            {
                NotifyNavigationFailed(navigationContext, navigationCallback, e);
            }
        }
 public void OnNavigationCanceled(INavigationContext context)
 {
     Should.NotBeNull(context, nameof(context));
     OnNavigationCanceledInternal(context);
     RaiseNavigated(context, true, null);
     Trace(nameof(OnNavigationCanceled), context);
 }
Example #21
0
        private void CompleteClose()
        {
            INavigationContext context = CreateCloseContext();

            OnClosed(_closeParameter, context);

            var result = ViewModelExtensions.GetOperationResult(ViewModel);

            OperationCallbackManager.SetResult(OperationResult.CreateResult(OperationType.WindowNavigation, ViewModel, result, context));

            _closeParameter = null;
            _shouldClose    = false;
            _isOpen         = false;
            TView view = View;

            if (view == null)
            {
                return;
            }
            ThreadManager.Invoke(ExecutionMode.AsynchronousOnUiThread, this, view, context, (@base, v, ctx) =>
            {
                @base.CleanupView(v);
                @base._viewManager
                .CleanupViewAsync(@base.ViewModel, ctx)
                .WithTaskExceptionHandler(@base.ViewModel);
            });
            View = null;
        }
 /// <summary>
 ///     Called when a page becomes the active page in a frame.
 /// </summary>
 public void OnNavigatedTo(INavigationContext context)
 {
     if (OnNavigatedToDelegate != null)
     {
         OnNavigatedToDelegate(context);
     }
 }
 /// <summary>
 ///     Initializes the <see cref="NavigatedEventArgs" />.
 /// </summary>
 public NavigatedEventArgs([NotNull] INavigationContext context, [NotNull] IViewModel viewModel)
 {
     Should.NotBeNull(context, "context");
     Should.NotBeNull(viewModel, "viewModel");
     _context   = context;
     _viewModel = viewModel;
 }
 public void OnNavigated(INavigationContext context)
 {
     Should.NotBeNull(context, nameof(context));
     HandleOpenedViewModels(context);
     OnNavigatedInternal(context);
     RaiseNavigated(context, false, null);
     Trace(nameof(OnNavigated), context);
 }
Example #25
0
        private void NotifyNavigationFailed(INavigationContext navigationContext, Action <IRegionNavigationResult> navigationCallback, Exception e)
        {
            var navigationResult =
                e != null ? new RegionNavigationResult(navigationContext, e) : new RegionNavigationResult(navigationContext, false);

            navigationCallback(navigationResult);
            RaiseNavigationFailed(navigationContext, e);
        }
 public Task <bool> OnNavigatingFromAsync(INavigationContext context)
 {
     if (OnNavigatingFromDelegate != null)
     {
         return(OnNavigatingFromDelegate(context));
     }
     return(Empty.TrueTask);
 }
 protected override void OnNavigatedFrom(INavigationContext context)
 {
     base.OnNavigatedFrom(context);
     if (context.NavigationMode == NavigationMode.Background)
     {
         _backgroundTime = DateTime.Now;
     }
 }
 public void OnNavigationFailed(INavigationContext context, Exception exception)
 {
     Should.NotBeNull(context, nameof(context));
     Should.NotBeNull(exception, nameof(exception));
     OnNavigationFailedInternal(context, exception);
     RaiseNavigated(context, false, exception);
     Trace(nameof(OnNavigationFailed), context);
 }
 protected override void OnNavigatedTo(INavigationContext context)
 {
     base.OnNavigatedTo(context);
     if (context.NavigationMode == NavigationMode.Foreground && _backgroundTime.HasValue)
     {
         Text = "Background time " + (DateTime.Now - _backgroundTime);
     }
 }
 public static void TraceNavigation(this IViewModel viewModel, INavigationContext ctx,
                                    IMessagePresenter messagePresenter, [CallerMemberName] string method = "")
 {
     //messagePresenter.ShowAsync(
     Debug.WriteLine(string.Format("Source “{0}”, method “{1}”, from “{2}” to “{3}”, mode “{4}”",
                                   GetName(viewModel), method, GetName(ctx.ViewModelFrom), GetName(ctx.ViewModelTo), ctx.NavigationMode),
                     "Navigation trace");
 }
 Task<bool> INavigableViewModel.OnNavigatingFrom(INavigationContext context)
 {
     this.TraceNavigation();
     return _messagePresenter
         .ShowAsync("Close SecondViewModel?", string.Empty, MessageButton.YesNo,
             MessageImage.Question)
         .TryExecuteSynchronously(task => task.Result == MessageResult.Yes);
 }
 private IViewModel TryTakeViewModelFromCache(INavigationContext context, object view)
 {
     if (CachePolicy == null)
     {
         return(null);
     }
     return(CachePolicy.TryTakeViewModelFromCache(context, view));
 }
        /// <summary>
        ///     Called when a view-model is no longer the active view-model in a frame.
        /// </summary>
        /// <param name="context">
        ///     The specified <see cref="INavigationContext" />.
        /// </param>
        void INavigableViewModel.OnNavigatedFrom(INavigationContext context)
        {
            var navigableViewModel = ViewModel as INavigableViewModel;

            if (navigableViewModel != null)
            {
                navigableViewModel.OnNavigatedFrom(context);
            }
        }
        // *** Methods ***

        public IViewLifetimeContext CreateView(string name, INavigationContext context)
        {
            IViewLifetimeContext view = _viewLifetimeContextFactory(name, null);

            if (view == null)
                throw new InvalidOperationException();

            return _viewLifetimeContextFactory(name, context);
        }
 protected bool TryCompleteOperationCallback([NotNull] IViewModel viewModel, [NotNull] INavigationContext context)
 {
     if (context.NavigationMode != NavigationMode.Back)
     {
         return(false);
     }
     CompleteOperationCallback(viewModel, context);
     return(true);
 }
Example #36
0
        // *** Methods ***

        public IViewLifetimeContext CreateView(string name, INavigationContext context)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentException(ResourceHelper.GetErrorResource("Exception_ArgumentException_StringIsNullOrEmpty"), nameof(name));

            if (context == null)
                throw new ArgumentNullException(nameof(context));

            // Create a new composition context for the page (this allows a sharing boundary to be formed)

            Export<CompositionContext> compositionContextExport = _compositionContextFactory.CreateExport();
            CompositionContext compositionContext = compositionContextExport.Value;

            // Since MEF does not support parameterized composition, inject a proxy INavigationContext into this sharing boundary

            NavigationContextProxy contextProxy = compositionContext.GetExport<INavigationContext>() as NavigationContextProxy;
            contextProxy.SetNavigationContext(context);

            // Setup the metadata contstraints (these are shared for both page and view model imports)

            Dictionary<string, object> metadataConstriants = new Dictionary<string, object>();
            metadataConstriants["PageName"] = name;

            // Get the requested page (if no suitable page is found then throw an exception)

            object page;

            if (!compositionContext.TryGetExport(new CompositionContract(typeof(object), "OkraPage", metadataConstriants), out page))
                throw new InvalidOperationException(string.Format(ResourceHelper.GetErrorResource("Exception_InvalidOperation_CannotNavigateAsPageIsNotFound"), name));

            // Get the requested view model (if one exists)

            object viewModel;

            if (compositionContext.TryGetExport(new CompositionContract(typeof(object), "OkraViewModel", metadataConstriants), out viewModel))
            {
                // Attach the view-model to the page
                // NB: Do this via a virtual method call to help with unit testing

                AttachViewModel(page, viewModel);
            }

            // Return a new IViewLifetimeContext

            return new ViewLifetimeContext(compositionContextExport, page, viewModel);
        }
 public virtual IViewModel TryTakeViewModelFromCache(INavigationContext context, object view)
 {
     view = GetView(view);
     var type = view.GetType();
     List<IViewModel> list;
     if (!_cachedViewModels.TryGetValue(type, out list) || list == null || list.Count == 0)
     {
         if (Tracer.TraceInformation)
             Tracer.Info("Navigation cache - the view model for the view {0} is not found in the cache, navigation mode: {1}", type, context.NavigationMode);
         return null;
     }
     IViewModel vm = list[0];
     list.RemoveAt(0);
     if (Tracer.TraceInformation)
         Tracer.Info("Navigation cache - the view model {0} for the view {1} was taken from the cache, navigation mode: {2}",
             vm.GetType(), type, context.NavigationMode);
     return vm;
 }
        public virtual void TryCacheViewModel(INavigationContext context, object view, IViewModel viewModel)
        {
            if (context.NavigationMode == NavigationMode.Back)
                return;
            view = ToolkitExtensions.GetUnderlyingView<object>(view);
            Type type = view.GetType();

            List<IViewModel> list;
            if (!_cachedViewModels.TryGetValue(type, out list))
            {
                list = new List<IViewModel>();
                _cachedViewModels[type] = list;
            }
            list.Insert(0, viewModel);
            if (Tracer.TraceInformation)
                Tracer.Info("Navigation cache - the view model {0} was cached, navigation mode: {1}, view: {2}",
                    viewModel.GetType(), context.NavigationMode, type);
        }
Example #39
0
 public $fileinputname$ViewModel(INavigationContext navigationContext)
     : base(navigationContext)
 Task<bool> INavigableViewModel.OnNavigatingFrom(INavigationContext context)
 {
     this.TraceNavigation(context);
     return Empty.TrueTask;
 }
 void INavigableViewModel.OnNavigatedTo(INavigationContext context)
 {
     this.TraceNavigation(context);
 }
 private void TryCacheViewModel(INavigationContext context, object view, IViewModel viewModel)
 {
     if (CachePolicy != null && view != null && viewModel != null)
         CachePolicy.TryCacheViewModel(context, view, viewModel);
 }
 public ItemDetailViewModel(INavigationContext navigationContext)
     : base(navigationContext)
 {
 }
 public static void TraceNavigation(this IViewModel viewModel, INavigationContext ctx, [CallerMemberName] string method = "")
 {
     Tracer.Warn("Source {0}, method {1}, from {2} to {3} mode {4}", GetName(viewModel), method, GetName(ctx.ViewModelFrom), GetName(ctx.ViewModelTo),
         ctx.NavigationMode);
 }
            // *** Methods ***

            public IViewLifetimeContext CreateView(string name, INavigationContext context)
            {
                switch (name)
                {
                    case "ShareTarget":
                        return new MockViewLifetimeContext("ShareTarget", "ViewModel", context, pageType: typeof(MockShareTargetPageElement), viewModelType: typeof(MockShareTargetPageElement));
                    default:
                        throw new InvalidOperationException();
                }
            }
 /// <summary>
 ///     Invokes the <see cref="Navigated" /> event.
 /// </summary>
 protected virtual void RaiseNavigated(INavigationContext ctx)
 {
     var handler = Navigated;
     if (handler != null)
         handler(this, new NavigatedEventArgs(ctx));
 }
 /// <summary>
 ///     Called when a view-model becomes the active view-model in a frame.
 /// </summary>
 /// <param name="viewModel">The specified <see cref="IViewModel"/></param>
 /// <param name="context">
 ///     The specified <see cref="INavigationContext" />.
 /// </param>
 protected virtual void OnNavigatedTo(IViewModel viewModel, INavigationContext context)
 {
     var navVm = viewModel as INavigableViewModel;
     if (navVm != null)
         navVm.OnNavigatedTo(context);
 }
Example #48
0
 public ItemsViewModel(INavigationContext navigationContext)
     : base(navigationContext)
 {
     Initialize();
 }
        private void OnNavigated(INavigationContext context)
        {
            var vmFrom = context.ViewModelFrom;
            var vmTo = context.ViewModelTo;
            var mode = context.NavigationMode;
            //only this mode allows to renavigate.
            if (ReferenceEquals(vmFrom, vmTo) && mode != NavigationMode.Refresh && mode != NavigationMode.Reset && mode != NavigationMode.Undefined)
            {
                if (vmFrom != null)
                    Tracer.Warn("Possible bug in navigation, navigate to the same view model with mode " + mode);
                return;
            }
            CurrentViewModel = vmTo;
            if (vmFrom != null)
            {
                var navigableViewModel = vmFrom as INavigableViewModel;
                if (navigableViewModel != null)
                    navigableViewModel.OnNavigatedFrom(context);
            }

            var closeableViewModel = vmTo as ICloseableViewModel;
            if (closeableViewModel != null && !(closeableViewModel.CloseCommand is CloseCommandWrapper))
            {
                closeableViewModel.Closed += _closeViewModelHandler;
                closeableViewModel.CloseCommand = new CloseCommandWrapper(closeableViewModel.CloseCommand, this, closeableViewModel);
            }

            if (vmTo != null)
                OnNavigatedTo(vmTo, context);
            RaiseNavigated(context);
            if (vmFrom != null && TryCompleteOperationCallback(vmFrom, context))
                OnViewModelClosed(vmFrom, context, this, false);
            if (Tracer.TraceInformation)
                Tracer.Info("Navigated from '{0}' to '{1}', navigation mode '{2}'", vmFrom, vmTo, mode);
        }
 public NavigatedEventArgs([NotNull]INavigationContext context)
 {
     Should.NotBeNull(context, nameof(context));
     _context = context;
 }
 private void CancelCurrentNavigation(INavigationContext context)
 {
     var callback = _currentCallback;
     if (callback != null)
     {
         callback.Invoke(OperationResult.CreateCancelResult<bool?>(OperationType.PageNavigation, this, context));
         _currentCallback = null;
         _navigationTargetVm = null;
     }
     var tcs = _navigatedTcs;
     if (tcs != null)
     {
         _navigatedTcs = null;
         tcs.TrySetCanceled();
     }
 }
 private IViewModel TryTakeViewModelFromCache(INavigationContext context, object view)
 {
     if (CachePolicy == null)
         return null;
     return CachePolicy.TryTakeViewModelFromCache(context, view);
 }
Example #53
0
 public HomeController(IDocumentStore documentStore, INavigationContext navigationContext, IBrickPileContext context)
 {
     this.documentStore = documentStore;
 }
 /// <summary>
 ///     Called just before a view-model is no longer the active view-model in a frame.
 /// </summary>
 /// <param name="viewModel">The specified <see cref="IViewModel"/></param>
 /// <param name="context">
 ///     The specified <see cref="INavigationContext" />.
 /// </param>
 protected virtual Task<bool> OnNavigatingFrom([NotNull] IViewModel viewModel, INavigationContext context)
 {
     return viewModel.TryCloseAsync(context, context);
 }
Example #55
0
 public SplitViewModel(INavigationContext navigationContext)
     : base(navigationContext)
 {
     ClearSelectionCommand = new DelegateCommand(ClearSelection);
 }
 void INavigableViewModel.OnNavigatedFrom(INavigationContext context)
 {
     this.TraceNavigation();
 }
 public void OnNavigatedTo(INavigationContext context)
 {
     if (OnNavigatedToDelegate != null)
         OnNavigatedToDelegate(context);
 }
 public SectionViewModel(INavigationContext navigationContext)
     : base(navigationContext)
 {
 }
            // *** Constructors ***

            public MockViewLifetimeContext(string pageName, string viewModelName, INavigationContext navigationContext, Type pageType = null, Type viewModelType = null)
            {
                this.PageName = pageName;
                this.NavigationContext = navigationContext;

                if (pageName != null)
                    View = Activator.CreateInstance(pageType ?? typeof(MockPageElement));

                if (viewModelName != null)
                    ViewModel = Activator.CreateInstance(viewModelType ?? typeof(MockPageElement));
            }
        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);
        }