-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.xaml.cs
58 lines (54 loc) · 3.55 KB
/
App.xaml.cs
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
using DevExpress.Mvvm.ModuleInjection;
using System.Windows;
namespace ViewModelGeneratorSample {
public partial class App : Application {
Bootstrapper Bootstrapper { get; set; }
protected override void OnStartup(StartupEventArgs e) {
base.OnStartup(e);
Bootstrapper = new Bootstrapper();
Bootstrapper.Run();
}
}
public class Bootstrapper {
IModuleManager Manager { get { return ModuleManager.DefaultManager; } }
void RegisterModules() {
Manager.Register(Regions.ViewContent, new Module(AppModules.Login, () => new LoginViewModel(), typeof(LoginView)));
Manager.Register(Regions.ViewContent, new Module(AppModules.Property, () => new PropertiesViewModel(), typeof(PropertiesView)));
Manager.Register(Regions.ViewContent, new Module(AppModules.Command, () => new CommandsViewModel(), typeof(CommandsView)));
Manager.Register(Regions.ViewContent, new Module(AppModules.AsyncCommand, () => new AsyncCommandsViewModel(), typeof(AsyncCommandsView)));
Manager.Register(Regions.ViewContent, new Module(AppModules.DataErrorInfo, () => new DataErrorInfoViewModel(), typeof(DataErrorInfoView)));
Manager.Register(Regions.ViewContent, new Module(AppModules.Services, () => new ServicesViewModel(), typeof(ServicesView)));
Manager.Register(Regions.Navigation, new Module(AppModules.Login, () => new NavigationItem(AppModules.Login), typeof(NavigationView)));
Manager.Register(Regions.Navigation, new Module(AppModules.Property, () => new NavigationItem(AppModules.Property), typeof(NavigationView)));
Manager.Register(Regions.Navigation, new Module(AppModules.Command, () => new NavigationItem(AppModules.Command), typeof(NavigationView)));
Manager.Register(Regions.Navigation, new Module(AppModules.AsyncCommand, () => new NavigationItem(AppModules.AsyncCommand), typeof(NavigationView)));
Manager.Register(Regions.Navigation, new Module(AppModules.DataErrorInfo, () => new NavigationItem(AppModules.DataErrorInfo), typeof(NavigationView)));
Manager.Register(Regions.Navigation, new Module(AppModules.Services, () => new NavigationItem(AppModules.Services), typeof(NavigationView)));
}
void InjectModules() {
Manager.Inject(Regions.Navigation, AppModules.Login);
Manager.Inject(Regions.Navigation, AppModules.Property);
Manager.Inject(Regions.Navigation, AppModules.Command);
Manager.Inject(Regions.Navigation, AppModules.AsyncCommand);
Manager.Inject(Regions.Navigation, AppModules.DataErrorInfo);
Manager.Inject(Regions.Navigation, AppModules.Services);
}
void ConfigureNavigation() => Manager.GetEvents(Regions.Navigation).Navigation += OnNavigation;
void ShowMainWindow() {
Application.Current.MainWindow = new MainWindow();
Application.Current.MainWindow.Show();
}
void ShowOverview() => Manager.InjectOrNavigate(Regions.ViewContent, AppModules.Login);
void OnNavigation(object sender, NavigationEventArgs e) {
if(e.NewViewModelKey != null)
Manager.InjectOrNavigate(Regions.ViewContent, e.NewViewModelKey);
}
public void Run() {
RegisterModules();
InjectModules();
ConfigureNavigation();
ShowMainWindow();
ShowOverview();
}
}
}