/// <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()); }
/// <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); }
/// <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()); }
/// <summary> /// Returns the currently visible ViewModel /// </summary> public static IRoutableViewModel GetCurrentViewModel(this RoutingState This) { return(This.NavigationStack.LastOrDefault()); }
/// <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()); }