-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathReactiveUserControl.cs
52 lines (45 loc) · 1.67 KB
/
ReactiveUserControl.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
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
using System.Windows.Forms;
namespace ReactiveUI.Winforms;
/// <summary>
/// This is an UserControl that is both and UserControl and has a ReactiveObject powers
/// (i.e. you can call RaiseAndSetIfChanged).
/// </summary>
/// <typeparam name="TViewModel">The type of the view model.</typeparam>
/// <seealso cref="UserControl" />
/// <seealso cref="IViewFor{TViewModel}" />
public partial class ReactiveUserControl<TViewModel> : UserControl, IViewFor<TViewModel>
where TViewModel : class
{
/// <summary>
/// Initializes a new instance of the <see cref="ReactiveUserControl{TViewModel}"/> class.
/// </summary>
public ReactiveUserControl() => InitializeComponent();
/// <inheritdoc/>
[Category("ReactiveUI")]
[Description("The ViewModel.")]
[Bindable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public TViewModel? ViewModel { get; set; }
/// <inheritdoc/>
object? IViewFor.ViewModel
{
get => ViewModel;
set => ViewModel = (TViewModel?)value;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing)
{
components?.Dispose();
}
base.Dispose(disposing);
}
}