2020-01-06 04:49:11 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ReactiveUI;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack
|
|
|
|
|
{
|
|
|
|
|
public static class IViewForExt
|
|
|
|
|
{
|
2021-01-01 18:21:07 +00:00
|
|
|
|
public static IReactiveBinding<TView, TProp> OneWayBindStrict<TViewModel, TView, TProp>(
|
2020-01-06 04:49:11 +00:00
|
|
|
|
this TView view,
|
|
|
|
|
TViewModel viewModel,
|
|
|
|
|
Expression<Func<TViewModel, TProp>> vmProperty,
|
|
|
|
|
Expression<Func<TView, TProp>> viewProperty)
|
|
|
|
|
where TViewModel : class
|
|
|
|
|
where TView : class, IViewFor
|
|
|
|
|
{
|
|
|
|
|
return view.OneWayBind(
|
|
|
|
|
viewModel: viewModel,
|
|
|
|
|
vmProperty: vmProperty,
|
|
|
|
|
viewProperty: viewProperty);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-01 18:21:07 +00:00
|
|
|
|
public static IReactiveBinding<TView, TOut> OneWayBindStrict<TViewModel, TView, TProp, TOut>(
|
2020-01-06 04:49:11 +00:00
|
|
|
|
this TView view,
|
|
|
|
|
TViewModel viewModel,
|
|
|
|
|
Expression<Func<TViewModel, TProp>> vmProperty,
|
|
|
|
|
Expression<Func<TView, TOut>> viewProperty,
|
|
|
|
|
Func<TProp, TOut> selector)
|
|
|
|
|
where TViewModel : class
|
|
|
|
|
where TView : class, IViewFor
|
|
|
|
|
{
|
|
|
|
|
return view.OneWayBind(
|
|
|
|
|
viewModel: viewModel,
|
|
|
|
|
vmProperty: vmProperty,
|
|
|
|
|
viewProperty: viewProperty,
|
|
|
|
|
selector: selector);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-01 18:21:07 +00:00
|
|
|
|
public static IReactiveBinding<TView, (object view, bool isViewModel)> BindStrict<TViewModel, TView, TProp>(
|
2020-01-06 04:49:11 +00:00
|
|
|
|
this TView view,
|
|
|
|
|
TViewModel viewModel,
|
|
|
|
|
Expression<Func<TViewModel, TProp>> vmProperty,
|
|
|
|
|
Expression<Func<TView, TProp>> viewProperty)
|
|
|
|
|
where TViewModel : class
|
|
|
|
|
where TView : class, IViewFor
|
|
|
|
|
{
|
|
|
|
|
return view.Bind(
|
|
|
|
|
viewModel: viewModel,
|
|
|
|
|
vmProperty: vmProperty,
|
|
|
|
|
viewProperty: viewProperty);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-01 18:21:07 +00:00
|
|
|
|
public static IReactiveBinding<TView, (object view, bool isViewModel)> BindStrict<TViewModel, TView, TVMProp, TVProp, TDontCare>(
|
2020-01-20 21:59:26 +00:00
|
|
|
|
this TView view,
|
|
|
|
|
TViewModel viewModel,
|
|
|
|
|
Expression<Func<TViewModel, TVMProp>> vmProperty,
|
|
|
|
|
Expression<Func<TView, TVProp>> viewProperty,
|
|
|
|
|
IObservable<TDontCare> signalViewUpdate,
|
|
|
|
|
Func<TVMProp, TVProp> vmToViewConverter,
|
|
|
|
|
Func<TVProp, TVMProp> viewToVmConverter)
|
|
|
|
|
where TViewModel : class
|
|
|
|
|
where TView : class, IViewFor
|
|
|
|
|
{
|
|
|
|
|
return view.Bind(
|
|
|
|
|
viewModel: viewModel,
|
|
|
|
|
vmProperty: vmProperty,
|
|
|
|
|
viewProperty: viewProperty,
|
|
|
|
|
signalViewUpdate: signalViewUpdate,
|
|
|
|
|
vmToViewConverter: vmToViewConverter,
|
|
|
|
|
viewToVmConverter: viewToVmConverter);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-01 18:21:07 +00:00
|
|
|
|
public static IReactiveBinding<TView, (object view, bool isViewModel)> BindStrict<TViewModel, TView, TVMProp, TVProp>(
|
2020-01-06 04:49:11 +00:00
|
|
|
|
this TView view,
|
2020-01-14 04:12:24 +00:00
|
|
|
|
TViewModel viewModel,
|
2020-01-06 04:49:11 +00:00
|
|
|
|
Expression<Func<TViewModel, TVMProp>> vmProperty,
|
2020-01-14 04:12:24 +00:00
|
|
|
|
Expression<Func<TView, TVProp>> viewProperty,
|
|
|
|
|
Func<TVMProp, TVProp> vmToViewConverter,
|
2020-01-06 04:49:11 +00:00
|
|
|
|
Func<TVProp, TVMProp> viewToVmConverter)
|
|
|
|
|
where TViewModel : class
|
|
|
|
|
where TView : class, IViewFor
|
|
|
|
|
{
|
|
|
|
|
return view.Bind(
|
|
|
|
|
viewModel: viewModel,
|
|
|
|
|
vmProperty: vmProperty,
|
|
|
|
|
viewProperty: viewProperty,
|
|
|
|
|
vmToViewConverter: vmToViewConverter,
|
|
|
|
|
viewToVmConverter: viewToVmConverter);
|
|
|
|
|
}
|
2020-01-14 04:12:24 +00:00
|
|
|
|
|
|
|
|
|
public static IDisposable BindToStrict<TValue, TTarget>(
|
|
|
|
|
this IObservable<TValue> @this,
|
|
|
|
|
TTarget target,
|
|
|
|
|
Expression<Func<TTarget, TValue>> property)
|
|
|
|
|
where TTarget : class
|
|
|
|
|
{
|
2020-01-20 21:59:26 +00:00
|
|
|
|
return @this
|
|
|
|
|
.ObserveOnGuiThread()
|
|
|
|
|
.BindTo<TValue, TTarget, TValue>(target, property);
|
2020-01-14 04:12:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Just a function to signify a field is being used, so it triggers compile errors if it changes
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void MarkAsNeeded<TView, TViewModel, TVMProp>(
|
|
|
|
|
this TView view,
|
|
|
|
|
TViewModel viewModel,
|
|
|
|
|
Expression<Func<TViewModel, TVMProp>> vmProperty)
|
|
|
|
|
where TViewModel : class
|
|
|
|
|
where TView : class, IViewFor
|
|
|
|
|
{
|
|
|
|
|
}
|
2020-01-06 04:49:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|