2019-10-30 19:39:12 +00:00
|
|
|
|
using ReactiveUI;
|
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Reactive.Disposables;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-21 15:45:00 +00:00
|
|
|
|
private readonly Lazy<CompositeDisposable> _compositeDisposable = new Lazy<CompositeDisposable>();
|
|
|
|
|
public CompositeDisposable CompositeDisposable => _compositeDisposable.Value;
|
2019-10-30 19:39:12 +00:00
|
|
|
|
|
|
|
|
|
public virtual void Dispose()
|
|
|
|
|
{
|
2019-11-21 15:45:00 +00:00
|
|
|
|
if (_compositeDisposable.IsValueCreated)
|
2019-10-30 19:39:12 +00:00
|
|
|
|
{
|
2019-11-21 15:45:00 +00:00
|
|
|
|
_compositeDisposable.Value.Dispose();
|
2019-10-30 19:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static void WireNotifyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!(d is UserControlRx control)) return;
|
2019-11-21 15:04:33 +00:00
|
|
|
|
if (Equals(e.OldValue, e.NewValue)) return;
|
2019-10-30 19:39:12 +00:00
|
|
|
|
control.RaisePropertyChanged(e.Property.Name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|