Class RoutingState
- Namespace
- ReactiveUI
- Assembly
- ReactiveUI.dll
RoutingState manages the ViewModel Stack and allows ViewModels to navigate to other ViewModels.
[DataContract]
[RequiresDynamicCode("RoutingState uses RxApp and ReactiveCommand which require dynamic code generation")]
[RequiresUnreferencedCode("RoutingState uses RxApp and ReactiveCommand which may require unreferenced code")]
public class RoutingState : ReactiveObject, IReactiveNotifyPropertyChanged<IReactiveObject>, IHandleObservableErrors, IReactiveObject, INotifyPropertyChanged, INotifyPropertyChanging, IEnableLogger
- Inheritance
-
Routing
State
- Implements
-
IEnable
Logger
- Inherited Members
- Extension Methods
Examples
public class ShellViewModel : ReactiveObject, IScreen
{
public RoutingState Router { get; } = new();
public ShellViewModel()
{
Router.Navigate.Execute(new HomeViewModel(this)).Subscribe();
}
public void ShowDetails() =>
Router.Navigate.Execute(new DetailsViewModel(this)).Subscribe();
public void GoBack() =>
Router.NavigateBack.Execute(Unit.Default).Subscribe();
}
public partial class ShellView : ReactiveUserControl<ShellViewModel>
{
public ShellView()
{
this.WhenActivated(disposables =>
ViewModel!.Router.CurrentViewModel
.Subscribe(viewModel => contentHost.NavigateTo(viewModel))
.DisposeWith(disposables));
}
}
Remarks
Use Routing
Constructors
RoutingState(IScheduler?)
Initializes a new instance of the Routing
[RequiresDynamicCode("RoutingState uses ReactiveCommand which requires dynamic code generation.")]
[RequiresUnreferencedCode("RoutingState uses ReactiveCommand which may require unreferenced code.")]
public RoutingState(IScheduler? scheduler = null)
Parameters
schedulerISchedulerA scheduler for where to send navigation changes to.
Properties
CurrentViewModel
Gets or sets the observable that yields the currently active view model whenever the navigation stack changes.
[IgnoreDataMember]
[JsonIgnore]
public IObservable<IRoutableViewModel> CurrentViewModel { get; protected set; }
Property Value
Navigate
Gets or sets a command that adds a new element to the navigation stack. The command argument must implement IRoutable
[IgnoreDataMember]
[JsonIgnore]
public ReactiveCommand<IRoutableViewModel, IRoutableViewModel> Navigate { get; protected set; }
Property Value
NavigateAndReset
Gets or sets a command that replaces the entire navigation stack with the supplied view model, effectively resetting navigation history.
[IgnoreDataMember]
[JsonIgnore]
public ReactiveCommand<IRoutableViewModel, IRoutableViewModel> NavigateAndReset { get; protected set; }
Property Value
NavigateBack
Gets or sets a command which will navigate back to the previous element in the stack and emits the new current view model. The command can only execute when at least two view models exist in the stack.
[IgnoreDataMember]
[JsonIgnore]
public ReactiveCommand<Unit, IRoutableViewModel> NavigateBack { get; protected set; }
Property Value
NavigationChanged
Gets or sets an observable that signals detailed change sets for the navigation stack, enabling reactive views to animate push/pop operations.
[IgnoreDataMember]
[JsonIgnore]
public IObservable<IChangeSet<IRoutableViewModel>> NavigationChanged { get; protected set; }
Property Value
NavigationStack
Gets or sets the current navigation stack, with the last element representing the active view model.
[DataMember]
[JsonRequired]
public ObservableCollection<IRoutableViewModel> NavigationStack { get; set; }