forked from PeteGoo/ReactiveUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewModelViewHost.cs
More file actions
39 lines (35 loc) · 1.43 KB
/
ViewModelViewHost.cs
File metadata and controls
39 lines (35 loc) · 1.43 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
using System;
using System.Windows;
using System.Windows.Controls;
using ReactiveUI.Xaml;
namespace ReactiveUI.Routing
{
public class ViewModelViewHost : ContentControl
{
public IReactiveNotifyPropertyChanged ViewModel {
get { return (IReactiveNotifyPropertyChanged)GetValue(ViewModelProperty); }
set { SetValue(ViewModelProperty, value); }
}
public static readonly DependencyProperty ViewModelProperty =
DependencyProperty.Register("ViewModel", typeof(IReactiveNotifyPropertyChanged), typeof(ViewModelViewHost), new PropertyMetadata(null));
public object DefaultContent {
get { return (object)GetValue(DefaultContentProperty); }
set { SetValue(DefaultContentProperty, value); }
}
public static readonly DependencyProperty DefaultContentProperty =
DependencyProperty.Register("DefaultContent", typeof(object), typeof(ViewModelViewHost), new PropertyMetadata(null));
public ViewModelViewHost()
{
this.ObservableFromDP(x => x.ViewModel)
.Subscribe(vm => {
if (vm.Value == null) {
Content = DefaultContent;
return;
}
var view = RxRouting.ResolveView(vm.Value);
view.ViewModel = vm.Value;
Content = view;
});
}
}
}