mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
UserControlRx implements ReactiveUserControl. Properties moved to WhenActivated
This commit is contained in:
parent
36d73b82f0
commit
04b2d13499
@ -4,10 +4,12 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:icon="http://metro.mahapps.com/winfx/xaml/iconpacks"
|
||||
xmlns:lib="clr-namespace:Wabbajack.Lib;assembly=Wabbajack.Lib"
|
||||
xmlns:local="clr-namespace:Wabbajack"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
x:TypeArguments="lib:ViewModel"
|
||||
ClipToBounds="True"
|
||||
mc:Ignorable="d">
|
||||
<UserControl.Resources>
|
||||
|
@ -1,15 +1,20 @@
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Wabbajack.Lib;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for DetailImageView.xaml
|
||||
/// </summary>
|
||||
public partial class DetailImageView : UserControlRx
|
||||
public partial class DetailImageView : UserControlRx<ViewModel>
|
||||
{
|
||||
public ImageSource Image
|
||||
{
|
||||
@ -51,30 +56,36 @@ namespace Wabbajack
|
||||
public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(nameof(Description), typeof(string), typeof(DetailImageView),
|
||||
new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, WireNotifyPropertyChanged));
|
||||
|
||||
private readonly ObservableAsPropertyHelper<bool> _showAuthor;
|
||||
public bool ShowAuthor => _showAuthor.Value;
|
||||
[Reactive]
|
||||
public bool ShowAuthor { get; private set; }
|
||||
|
||||
private readonly ObservableAsPropertyHelper<bool> _showDescription;
|
||||
public bool ShowDescription => _showDescription.Value;
|
||||
[Reactive]
|
||||
public bool ShowDescription { get; private set; }
|
||||
|
||||
private readonly ObservableAsPropertyHelper<bool> _showTitle;
|
||||
public bool ShowTitle => _showTitle.Value;
|
||||
[Reactive]
|
||||
public bool ShowTitle { get; private set; }
|
||||
|
||||
public DetailImageView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_showAuthor = this.WhenAny(x => x.Author)
|
||||
.Select(x => !string.IsNullOrWhiteSpace(x))
|
||||
.ToProperty(this, nameof(ShowAuthor));
|
||||
this.WhenActivated(dispose =>
|
||||
{
|
||||
this.WhenAny(x => x.Author)
|
||||
.Select(x => !string.IsNullOrWhiteSpace(x))
|
||||
.Subscribe(x => ShowAuthor = x)
|
||||
.DisposeWith(dispose);
|
||||
|
||||
_showDescription = this.WhenAny(x => x.Description)
|
||||
.Select(x => !string.IsNullOrWhiteSpace(x))
|
||||
.ToProperty(this, nameof(ShowDescription));
|
||||
this.WhenAny(x => x.Description)
|
||||
.Select(x => !string.IsNullOrWhiteSpace(x))
|
||||
.Subscribe(x => ShowDescription = x)
|
||||
.DisposeWith(dispose);
|
||||
|
||||
_showTitle = this.WhenAny(x => x.Title)
|
||||
.Select(x => !string.IsNullOrWhiteSpace(x))
|
||||
.ToProperty(this, nameof(ShowTitle));
|
||||
this.WhenAny(x => x.Title)
|
||||
.Select(x => !string.IsNullOrWhiteSpace(x))
|
||||
.Subscribe(x => ShowTitle = x)
|
||||
.DisposeWith(dispose);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,13 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:lib="clr-namespace:Wabbajack.Lib;assembly=Wabbajack.Lib"
|
||||
xmlns:local="clr-namespace:Wabbajack"
|
||||
xmlns:mahapps="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
x:TypeArguments="lib:ViewModel"
|
||||
BorderThickness="0"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
|
@ -2,13 +2,17 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using ReactiveUI;
|
||||
using System;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Wabbajack.Lib;
|
||||
using System.Reactive.Disposables;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for TopProgressView.xaml
|
||||
/// </summary>
|
||||
public partial class TopProgressView : UserControlRx
|
||||
public partial class TopProgressView : UserControlRx<ViewModel>
|
||||
{
|
||||
public double ProgressPercent
|
||||
{
|
||||
@ -50,18 +54,22 @@ namespace Wabbajack
|
||||
public static readonly DependencyProperty ShadowMarginProperty = DependencyProperty.Register(nameof(ShadowMargin), typeof(bool), typeof(TopProgressView),
|
||||
new FrameworkPropertyMetadata(true));
|
||||
|
||||
private readonly ObservableAsPropertyHelper<double> _ProgressOpacityPercent;
|
||||
public double ProgressOpacityPercent => _ProgressOpacityPercent.Value;
|
||||
[Reactive]
|
||||
public double ProgressOpacityPercent { get; private set; }
|
||||
|
||||
public TopProgressView()
|
||||
{
|
||||
InitializeComponent();
|
||||
_ProgressOpacityPercent = this.WhenAny(x => x.ProgressPercent)
|
||||
.Select(x =>
|
||||
{
|
||||
return 0.3 + x * 0.7;
|
||||
})
|
||||
.ToProperty(this, nameof(ProgressOpacityPercent));
|
||||
this.WhenActivated(dispose =>
|
||||
{
|
||||
this.WhenAny(x => x.ProgressPercent)
|
||||
.Select(x =>
|
||||
{
|
||||
return 0.3 + x * 0.7;
|
||||
})
|
||||
.Subscribe(x => ProgressOpacityPercent = x)
|
||||
.DisposeWith(dispose);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,40 +7,6 @@ using System.Windows.Controls;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
public class UserControlRx : UserControl, IDisposable, IReactiveObject
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
public event PropertyChangingEventHandler PropertyChanging;
|
||||
|
||||
public void RaisePropertyChanging(PropertyChangingEventArgs args)
|
||||
{
|
||||
PropertyChanging?.Invoke(this, args);
|
||||
}
|
||||
|
||||
public void RaisePropertyChanged(PropertyChangedEventArgs args)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, args);
|
||||
}
|
||||
|
||||
private readonly Lazy<CompositeDisposable> _compositeDisposable = new Lazy<CompositeDisposable>();
|
||||
public CompositeDisposable CompositeDisposable => _compositeDisposable.Value;
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
if (_compositeDisposable.IsValueCreated)
|
||||
{
|
||||
_compositeDisposable.Value.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void WireNotifyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (!(d is UserControlRx control)) return;
|
||||
if (Equals(e.OldValue, e.NewValue)) return;
|
||||
control.RaisePropertyChanged(e.Property.Name);
|
||||
}
|
||||
}
|
||||
|
||||
public class UserControlRx<TViewModel> : ReactiveUserControl<TViewModel>, IReactiveObject
|
||||
where TViewModel : class
|
||||
{
|
||||
@ -59,7 +25,7 @@ namespace Wabbajack
|
||||
|
||||
protected static void WireNotifyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (!(d is UserControlRx control)) return;
|
||||
if (!(d is UserControlRx<TViewModel> control)) return;
|
||||
if (Equals(e.OldValue, e.NewValue)) return;
|
||||
control.RaisePropertyChanged(e.Property.Name);
|
||||
}
|
||||
|
@ -614,6 +614,8 @@
|
||||
<ItemGroup>
|
||||
<SplashScreen Include="Resources\Wabba_Mouth_Small.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Folder Include="Interfaces\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user