committed by
GitHub
35 changed files with 334 additions and 76 deletions
@ -0,0 +1,44 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using Avalonia; |
|||
using Avalonia.VisualTree; |
|||
using Avalonia.Controls; |
|||
using ReactiveUI; |
|||
|
|||
namespace Avalonia |
|||
{ |
|||
/// <summary>
|
|||
/// A ReactiveUI UserControl that implements <see cref="IViewFor{TViewModel}"/>
|
|||
/// and will activate your ViewModel automatically if it supports activation.
|
|||
/// </summary>
|
|||
/// <typeparam name="TViewModel">ViewModel type.</typeparam>
|
|||
public class ReactiveUserControl<TViewModel> : UserControl, IViewFor<TViewModel> where TViewModel : class |
|||
{ |
|||
public static readonly AvaloniaProperty<TViewModel> ViewModelProperty = AvaloniaProperty |
|||
.Register<ReactiveWindow<TViewModel>, TViewModel>(nameof(ViewModel)); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="ReactiveUserControl{TViewModel}"/> class.
|
|||
/// </summary>
|
|||
public ReactiveUserControl() |
|||
{ |
|||
DataContextChanged += (sender, args) => ViewModel = DataContext as TViewModel; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// The ViewModel.
|
|||
/// </summary>
|
|||
public TViewModel ViewModel |
|||
{ |
|||
get => GetValue(ViewModelProperty); |
|||
set => SetValue(ViewModelProperty, value); |
|||
} |
|||
|
|||
object IViewFor.ViewModel |
|||
{ |
|||
get => ViewModel; |
|||
set => ViewModel = (TViewModel)value; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using Avalonia; |
|||
using Avalonia.VisualTree; |
|||
using Avalonia.Controls; |
|||
using ReactiveUI; |
|||
|
|||
namespace Avalonia |
|||
{ |
|||
/// <summary>
|
|||
/// A ReactiveUI Window that implements <see cref="IViewFor{TViewModel}"/>
|
|||
/// and will activate your ViewModel automatically if it supports activation.
|
|||
/// </summary>
|
|||
/// <typeparam name="TViewModel">ViewModel type.</typeparam>
|
|||
public class ReactiveWindow<TViewModel> : Window, IViewFor<TViewModel> where TViewModel : class |
|||
{ |
|||
public static readonly AvaloniaProperty<TViewModel> ViewModelProperty = AvaloniaProperty |
|||
.Register<ReactiveWindow<TViewModel>, TViewModel>(nameof(ViewModel)); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="ReactiveWindow{TViewModel}"/> class.
|
|||
/// </summary>
|
|||
public ReactiveWindow() |
|||
{ |
|||
DataContextChanged += (sender, args) => ViewModel = DataContext as TViewModel; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// The ViewModel.
|
|||
/// </summary>
|
|||
public TViewModel ViewModel |
|||
{ |
|||
get => GetValue(ViewModelProperty); |
|||
set => SetValue(ViewModelProperty, value); |
|||
} |
|||
|
|||
object IViewFor.ViewModel |
|||
{ |
|||
get => ViewModel; |
|||
set => ViewModel = (TViewModel)value; |
|||
} |
|||
} |
|||
} |
|||
@ -1,4 +1,4 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<packages> |
|||
<package id="Cake" version="0.28.0" /> |
|||
<package id="Cake" version="0.30.0" /> |
|||
</packages> |
|||
|
|||
Loading…
Reference in new issue