diff --git a/NavigationSample/Models/INavigationControl.cs b/NavigationSample/Models/INavigationControl.cs index 99fad05..6b28c72 100644 --- a/NavigationSample/Models/INavigationControl.cs +++ b/NavigationSample/Models/INavigationControl.cs @@ -4,6 +4,7 @@ namespace NavigationSample.Models { public interface INavigationControl { + INavigationManager Manager { get; set; } bool IsContentEnabled { get; set; } bool IsDialogEnabled { get; set; } object Content { get; set; } diff --git a/NavigationSample/Models/INavigationManager.cs b/NavigationSample/Models/INavigationManager.cs index d73aa55..25d45a4 100644 --- a/NavigationSample/Models/INavigationManager.cs +++ b/NavigationSample/Models/INavigationManager.cs @@ -2,8 +2,8 @@ namespace NavigationSample.Models { public interface INavigationManager { - INavigationControl Control { get; set; } - INavigationStack Stack { get; set; } + INavigationControl Control { get; } + INavigationStack Stack { get; } void CloseContent(); void CloseLeftPane(); void CloseRightPane(); diff --git a/NavigationSample/Navigation/NavigationControlViewModel.cs b/NavigationSample/Navigation/NavigationControlViewModel.cs index ca3005a..97e49ee 100644 --- a/NavigationSample/Navigation/NavigationControlViewModel.cs +++ b/NavigationSample/Navigation/NavigationControlViewModel.cs @@ -8,6 +8,7 @@ namespace NavigationSample.ViewModels { public class NavigationControlViewModel : ReactiveObject, INavigationControl { + private INavigationManager _manager; private bool _isContentEnabled; private bool _isDialogEnabled; private object _content; @@ -17,7 +18,7 @@ namespace NavigationSample.ViewModels private object _dialog; private object _popup; - public NavigationControlViewModel(INavigationManager navigationManager) + public NavigationControlViewModel() { this.WhenAnyValue( x => x.Dialog, @@ -30,17 +31,22 @@ namespace NavigationSample.ViewModels .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => IsDialogEnabled = x is null); - CloseContentCommand = ReactiveCommand.Create(x => navigationManager.CloseContent()); + CloseContentCommand = ReactiveCommand.Create(x => _manager?.CloseContent()); - CloseLeftPaneCommand = ReactiveCommand.Create(x => navigationManager.CloseLeftPane()); + CloseLeftPaneCommand = ReactiveCommand.Create(x => _manager?.CloseLeftPane()); - CloseRightPaneCommand = ReactiveCommand.Create(x => navigationManager.CloseRightPane()); + CloseRightPaneCommand = ReactiveCommand.Create(x => _manager?.CloseRightPane()); - CloseStatusCommand = ReactiveCommand.Create(x => navigationManager.CloseStatus()); + CloseStatusCommand = ReactiveCommand.Create(x => _manager?.CloseStatus()); - CloseDialogCommand = ReactiveCommand.Create(x => navigationManager.CloseDialog()); + CloseDialogCommand = ReactiveCommand.Create(x => _manager?.CloseDialog()); - ClosePopupCommand = ReactiveCommand.Create(x => navigationManager.ClosePopup()); + ClosePopupCommand = ReactiveCommand.Create(x => _manager?.ClosePopup()); + } + public INavigationManager Manager + { + get => _manager; + set => this.RaiseAndSetIfChanged(ref _manager, value); } public bool IsContentEnabled diff --git a/NavigationSample/Navigation/NavigationManagerViewModel.cs b/NavigationSample/Navigation/NavigationManagerViewModel.cs index c39b261..a08d764 100644 --- a/NavigationSample/Navigation/NavigationManagerViewModel.cs +++ b/NavigationSample/Navigation/NavigationManagerViewModel.cs @@ -9,106 +9,95 @@ namespace NavigationSample.ViewModels { public static NavigationManagerViewModel Instance { get; private set; } - public static void Register() + public static void Register(INavigationControl control, INavigationStack stack) { - Instance = new NavigationManagerViewModel(); + Instance = new NavigationManagerViewModel(control, stack); } - private INavigationControl _control; - private INavigationStack _stack; - - private NavigationManagerViewModel() + private NavigationManagerViewModel(INavigationControl control, INavigationStack stack) { - Control = new NavigationControlViewModel(this); - Stack = new NavigationStackViewModel(); + Control = control; + Stack = stack; } - public INavigationControl Control - { - get => _control; - set => this.RaiseAndSetIfChanged(ref _control, value); - } + public INavigationControl Control { get; } - public INavigationStack Stack - { - get => _stack; - set => this.RaiseAndSetIfChanged(ref _stack, value); - } + public INavigationStack Stack { get; } public void CloseContent() { - Stack.ContentStack.Remove(_control.Content); - _control.Content = null; + Stack.ContentStack.Remove(Control.Content); + Control.Content = null; } public void CloseLeftPane() { - _control.LeftPane = null; + Control.LeftPane = null; } public void CloseRightPane() { - _control.RightPane = null; + Control.RightPane = null; } public void CloseStatus() { - _control.Status = null; + Control.Status = null; } public void CloseDialog() { - Stack.DialogStack.Remove(_control.Dialog); - _control.Dialog = null; + Stack.DialogStack.Remove(Control.Dialog); + Control.Dialog = null; } public void ClosePopup() { - _control.Popup = null; + Control.Popup = null; } public void ClearContent() { Stack.ContentStack.Clear(); - _control.Content = null; + Control.Content = null; } public void ClearDialog() { Stack.DialogStack.Clear(); - _control.Dialog = null; + Control.Dialog = null; } public void NavigateContent(object content) { - _control.Content = content; + Control.Content = content; Stack.ContentStack.Add(content); } public void NavigateLeftPane(object pane) { - _control.LeftPane = pane; + Control.LeftPane = pane; } public void NavigateRightPane(object pane) { - _control.RightPane = pane; + Control.RightPane = pane; } public void NavigateStatus(object pane) { - _control.Status = pane; + Control.Status = pane; } public void NavigateDialog(object dialog) { - _control.Dialog = dialog; + Control.Dialog = dialog; Stack.DialogStack.Add(dialog); } public void NavigatePopup(object popup) { - _control.Popup = popup; + Control.Popup = popup; } public void GoBackContent() @@ -125,7 +114,7 @@ namespace NavigationSample.ViewModels var back = Stack.ContentStack.LastOrDefault(); if (back is { }) { - _control.Content = back; + Control.Content = back; } } } @@ -144,7 +133,7 @@ namespace NavigationSample.ViewModels var back = Stack.DialogStack.LastOrDefault(); if (back is { }) { - _control.Dialog = back; + Control.Dialog = back; } } } diff --git a/NavigationSample/ViewModels/MainWindowViewModel.cs b/NavigationSample/ViewModels/MainWindowViewModel.cs index 2158a1d..883573a 100644 --- a/NavigationSample/ViewModels/MainWindowViewModel.cs +++ b/NavigationSample/ViewModels/MainWindowViewModel.cs @@ -1,16 +1,27 @@ -namespace NavigationSample.ViewModels +using NavigationSample.Models; + +namespace NavigationSample.ViewModels { public class MainWindowViewModel : ViewModelBase { public MainWindowViewModel() { - NavigationManagerViewModel.Register(); + Control = new NavigationControlViewModel(); + Stack = new NavigationStackViewModel(); + + NavigationManagerViewModel.Register(Control, Stack); + Manager = NavigationManagerViewModel.Instance; + Control.Manager = NavigationManagerViewModel.Instance; + NavigationManagerViewModel.Instance.NavigateLeftPane(new LeftPaneViewModel()); NavigationManagerViewModel.Instance.NavigateContent(new HomeViewModel()); NavigationManagerViewModel.Instance.NavigateStatus(new StatusViewModel()); - Navigation = NavigationManagerViewModel.Instance; } - public NavigationManagerViewModel Navigation { get; } + public INavigationControl Control { get; } + + public INavigationStack Stack { get; } + + public INavigationManager Manager { get; } } } diff --git a/NavigationSample/Views/MainWindow.axaml b/NavigationSample/Views/MainWindow.axaml index 3c862d0..98f738a 100644 --- a/NavigationSample/Views/MainWindow.axaml +++ b/NavigationSample/Views/MainWindow.axaml @@ -21,7 +21,7 @@ -