コード例 #1
0
        /// <summary>
        /// Returns the currently visible ViewModel.
        /// </summary>
        /// <param name="item">The routing state.</param>
        /// <returns>The matching ViewModel or null if none exists.</returns>
        public static IRoutableViewModel GetCurrentViewModel(this RoutingState item)
        {
            if (item == null)
            {
                throw new System.ArgumentNullException(nameof(item));
            }

            return(item.NavigationStack.LastOrDefault());
        }
コード例 #2
0
        /// <summary>
        /// Creates a ReactiveCommand which will, when invoked, navigate to the
        /// type specified by the type parameter via looking it up in the
        /// Dependency Resolver.
        /// </summary>
        public static IReactiveCommand NavigateCommandFor <T>(this RoutingState This)
            where T : IRoutableViewModel, new()
        {
            var ret = new ReactiveCommand <object>(This.Navigate.CanExecuteObservable, x => Observable.Return(x));

            ret.Select(_ => (IRoutableViewModel)Locator.Current.GetService <T>() ?? new T()).InvokeCommand(This.Navigate);

            return(ret);
        }
コード例 #3
0
        /// <summary>
        /// Locate the first ViewModel in the stack that matches a certain Type.
        /// </summary>
        /// <typeparam name="T">The view model type.</typeparam>
        /// <param name="item">The routing state.</param>
        /// <returns>The matching ViewModel or null if none exists.</returns>
        public static T FindViewModelInStack <T>(this RoutingState item)
            where T : IRoutableViewModel
        {
            if (item == null)
            {
                throw new System.ArgumentNullException(nameof(item));
            }

            return(item.NavigationStack.Reverse().OfType <T>().FirstOrDefault());
        }
コード例 #4
0
ファイル: RoutingState.cs プロジェクト: ccaunca/Projects
 /// <summary>
 /// Returns the currently visible ViewModel
 /// </summary>
 public static IRoutableViewModel GetCurrentViewModel(this RoutingState This)
 {
     return(This.NavigationStack.LastOrDefault());
 }
コード例 #5
0
ファイル: RoutingState.cs プロジェクト: ccaunca/Projects
 /// <summary>
 /// Locate the first ViewModel in the stack that matches a certain Type.
 /// </summary>
 /// <returns>The matching ViewModel or null if none exists.</returns>
 public static T FindViewModelInStack <T>(this RoutingState This)
     where T : IRoutableViewModel
 {
     return(This.NavigationStack.Reverse().OfType <T>().FirstOrDefault());
 }