-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.xaml.cs
48 lines (39 loc) · 1.47 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
using System.Windows;
using Example.ViewModels;
using Example.Views;
using PS.MVVM.Extensions;
using PS.MVVM.Services;
using PS.WPF.DataTemplate;
namespace Example;
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
{
protected override void OnStartup(StartupEventArgs e)
{
var viewResolverService = GetViewResolverService();
// Register views in default region
viewResolverService.AssociateTemplate<Item1ViewModel>(CreateDynamicDataTemplateForType<Item1View>());
viewResolverService.AssociateTemplate<Item2ViewModel>(CreateDynamicDataTemplateForType<Item2View>());
viewResolverService.AssociateTemplate<Item3ViewModel>((DataTemplate)Resources["Item3ViewDataTemplate"]);
base.OnStartup(e);
}
private DataTemplate CreateDynamicDataTemplateForType<T>()
{
// Demonstrates how to create DataTemplate for view model type using custom ViewDataTemplate from PS.WPF
return new ViewDataTemplate
{
ViewType = typeof(T)
};
}
private IViewResolverService GetViewResolverService()
{
var viewResolverService = new ViewResolverService();
// Service registration using ServiceLocator pattern
//GlobalServices.Register(viewResolverService);
// Service registration using Application.Resources
Resources[typeof(IViewResolverService)] = viewResolverService;
return viewResolverService;
}
}