Set current selected item with mouse

This commit is contained in:
2023-07-21 22:50:28 +02:00
parent b61c204e49
commit 73304131a9
3 changed files with 27 additions and 11 deletions

View File

@@ -6,16 +6,20 @@ public sealed class CombineLatestProperty<T1, T2, TResult> : DeclarativeProperty
private T1? _value1;
private T2? _value2;
public CombineLatestProperty(IDeclarativeProperty<T1> prop1, IDeclarativeProperty<T2> prop2, Func<T1?, T2?, Task<TResult>> func)
public CombineLatestProperty(
IDeclarativeProperty<T1> prop1,
IDeclarativeProperty<T2> prop2,
Func<T1?, T2?, Task<TResult>> func,
Action<TResult?>? setValueHook = null) : base(setValueHook)
{
ArgumentNullException.ThrowIfNull(prop1);
ArgumentNullException.ThrowIfNull(prop2);
_func = func;
_value1 = prop1.Value is null ? default : prop1.Value;
_value2 = prop2.Value is null ? default : prop2.Value;
prop1.Subscribe(async (value1, token) =>
{
_value1 = value1;

View File

@@ -3,10 +3,11 @@
public static class DeclarativePropertyHelpers
{
public static CombineLatestProperty<T1, T2, TResult> CombineLatest<T1, T2, TResult>(
IDeclarativeProperty<T1> prop1,
IDeclarativeProperty<T2> prop2,
Func<T1, T2, Task<TResult>> func)
=> new(prop1, prop2, func);
IDeclarativeProperty<T1> prop1,
IDeclarativeProperty<T2> prop2,
Func<T1, T2, Task<TResult>> func,
Action<TResult?>? setValueHook = null)
=> new(prop1, prop2, func, setValueHook);
}
public sealed class DeclarativeProperty<T> : DeclarativePropertyBase<T>
@@ -17,9 +18,9 @@ public sealed class DeclarativeProperty<T> : DeclarativePropertyBase<T>
public DeclarativeProperty(T initialValue, Action<T?>? setValueHook = null) : base(initialValue, setValueHook)
{
}
public async Task SetValue(T newValue, CancellationToken cancellationToken = default)
public async Task SetValue(T newValue, CancellationToken cancellationToken = default)
=> await SetNewValueAsync(newValue, cancellationToken);
}