-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMainWindowViewModel.cs
More file actions
109 lines (102 loc) · 3.55 KB
/
MainWindowViewModel.cs
File metadata and controls
109 lines (102 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using Lemon.ModuleNavigation.Abstractions;
using Lemon.ModuleNavigation.Core;
using ReactiveUI;
using System.Diagnostics;
using System.Reactive;
namespace Lemon.ModuleNavigation.SampleViewModel;
public class MainWindowViewModel : ReactiveObject, IServiceAware
{
private readonly INavigationService _navigationService;
private readonly IDialogService _dialogService;
private readonly IRegionManager _regionManager;
public MainWindowViewModel(INavigationService navigationService,
IDialogService dialogService,
IRegionManager regionManager,
IServiceProvider serviceProvider)
{
_dialogService = dialogService;
_regionManager = regionManager;
_navigationService = navigationService;
_navigationService.RequestViewNavigation("ContentRegion", "ViewAlpha");
ServiceProvider = serviceProvider;
NavigateToViewCommand = ReactiveCommand.Create<string>(content =>
{
var viewName = content;
var requestNew = false;
if (content.EndsWith(".RequestNew"))
{
viewName = content.Replace(".RequestNew", string.Empty);
requestNew = true;
}
_navigationService.RequestViewNavigation("ContentRegion", viewName, new NavigationParameters { { "requestNew", requestNew } });
_navigationService.RequestViewNavigation("TabRegion", viewName, new NavigationParameters { { "requestNew", requestNew } });
_navigationService.RequestViewNavigation("ItemsRegion", viewName, new NavigationParameters { { "requestNew", requestNew } });
});
ShowCommand = ReactiveCommand.Create<string>(content =>
{
var param = new DialogParameters
{
{ "parent", nameof(MainWindowViewModel) }
};
_dialogService.Show(content, null, param, result =>
{
Debug.WriteLine($"Call back:{result}");
});
Debug.WriteLine($"Show over!");
});
ShowDialogCommand = ReactiveCommand.CreateFromTask<string>(async content =>
{
var param = new DialogParameters
{
{ "parent", nameof(MainWindowViewModel) }
};
await _dialogService.ShowDialog(content,
null,
param,
result =>
{
Debug.WriteLine($"Call back:{result}");
});
Debug.WriteLine($"ShowDialog over!");
});
ShowDialogSyncCommand = ReactiveCommand.Create<string>(content =>
{
var param = new DialogParameters
{
{ "parent", nameof(MainWindowViewModel) }
};
var result = _dialogService.WaitShowDialog(content,
null,
param);
Debug.WriteLine($"ShowDialog over:{result}");
});
UnloadViewCommand = ReactiveCommand.Create<NavigationContext>((context) =>
{
_regionManager.RequestViewUnload(context);
});
}
public IServiceProvider ServiceProvider
{
get;
}
public ReactiveCommand<NavigationContext, Unit> UnloadViewCommand
{
get;
}
public ReactiveCommand<string, Unit> NavigateToViewCommand
{
get;
}
public ReactiveCommand<string, Unit> ShowCommand
{
get;
}
public ReactiveCommand<string, Unit> ShowDialogCommand
{
get;
}
public ReactiveCommand<string, Unit> ShowDialogSyncCommand
{
get;
}
}