forked from reactiveui/ReactiveUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReactiveUserControl.cs
More file actions
executable file
·64 lines (60 loc) · 2.17 KB
/
ReactiveUserControl.cs
File metadata and controls
executable file
·64 lines (60 loc) · 2.17 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
namespace ReactiveUI
{
#if NETFX_CORE
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
#else
using System.Windows;
using System.Windows.Controls;
#endif
/// <summary>
/// A <see cref="UserControl"/> that is reactive.
/// </summary>
/// <remarks>
/// <para>
/// This class is a <see cref="UserControl"/> that is also reactive. That is, it implements <see cref="IViewFor{TViewModel}"/>.
/// You can extend this class to get an implementation of <see cref="IViewFor{TViewModel}"/> rather than writing one yourself.
/// </para>
/// <para>
/// Note that the XAML for your control must specify the same base class, including the generic argument you provide for your view
/// model. To do this, use the <c>TypeArguments</c> attribute as follows:
/// <code>
/// <![CDATA[
/// <rxui:ReactiveUserControl
/// x:Class="views:YourView"
/// x:TypeArguments="vms:YourViewModel"
/// xmlns:rxui="http://reactiveui.net"
/// xmlns:views="clr-namespace:Foo.Bar.Views"
/// xmlns:vms="clr-namespace:Foo.Bar.ViewModels">
/// <!-- view XAML here -->
/// </rxui:ReactiveUserControl>
/// ]]>
/// </code>
/// </para>
/// </remarks>
/// <typeparam name="TViewModel">
/// The type of the view model backing the view.
/// </typeparam>
public abstract class ReactiveUserControl<TViewModel> :
UserControl, IViewFor<TViewModel>
where TViewModel : class
{
public TViewModel BindingRoot => ViewModel;
public static readonly DependencyProperty ViewModelProperty =
DependencyProperty.Register(
"ViewModel",
typeof(TViewModel),
typeof(ReactiveUserControl<TViewModel>),
new PropertyMetadata(null));
public TViewModel ViewModel
{
get { return (TViewModel)this.GetValue(ViewModelProperty); }
set { this.SetValue(ViewModelProperty, value); }
}
object IViewFor.ViewModel
{
get { return this.ViewModel; }
set { this.ViewModel = (TViewModel)value; }
}
}
}