This commit is contained in:
Wiesław Šoltés 2020-12-01 14:18:48 +00:00 коммит произвёл GitHub
Родитель 3ca7437ae5
Коммит bd56c01c7f
6 изменённых файлов: 57 добавлений и 50 удалений

Просмотреть файл

@ -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; }

Просмотреть файл

@ -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();

Просмотреть файл

@ -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<object>(x => navigationManager.CloseContent());
CloseContentCommand = ReactiveCommand.Create<object>(x => _manager?.CloseContent());
CloseLeftPaneCommand = ReactiveCommand.Create<object>(x => navigationManager.CloseLeftPane());
CloseLeftPaneCommand = ReactiveCommand.Create<object>(x => _manager?.CloseLeftPane());
CloseRightPaneCommand = ReactiveCommand.Create<object>(x => navigationManager.CloseRightPane());
CloseRightPaneCommand = ReactiveCommand.Create<object>(x => _manager?.CloseRightPane());
CloseStatusCommand = ReactiveCommand.Create<object>(x => navigationManager.CloseStatus());
CloseStatusCommand = ReactiveCommand.Create<object>(x => _manager?.CloseStatus());
CloseDialogCommand = ReactiveCommand.Create<object>(x => navigationManager.CloseDialog());
CloseDialogCommand = ReactiveCommand.Create<object>(x => _manager?.CloseDialog());
ClosePopupCommand = ReactiveCommand.Create<object>(x => navigationManager.ClosePopup());
ClosePopupCommand = ReactiveCommand.Create<object>(x => _manager?.ClosePopup());
}
public INavigationManager Manager
{
get => _manager;
set => this.RaiseAndSetIfChanged(ref _manager, value);
}
public bool IsContentEnabled

Просмотреть файл

@ -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;
}
}
}

Просмотреть файл

@ -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; }
}
}

Просмотреть файл

@ -21,7 +21,7 @@
</Design.DataContext>
<Panel Margin="{Binding #MainWindow.OffScreenMargin}">
<Panel Margin="{Binding #MainWindow.WindowDecorationMargin}">
<c:NavigationControl DataContext="{Binding Navigation.Control}"
<c:NavigationControl DataContext="{Binding Control}"
IsContentEnabled="{Binding IsContentEnabled}"
IsDialogEnabled="{Binding IsDialogEnabled}"
Content="{Binding Content}"