fixes
This commit is contained in:
@@ -21,7 +21,7 @@ public class ContentControlHandler :
|
|||||||
{
|
{
|
||||||
if (content is IActivated activated)
|
if (content is IActivated activated)
|
||||||
{
|
{
|
||||||
await activated.Activated();
|
await activated.OnActivated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ public class ContentControlHandler :
|
|||||||
{
|
{
|
||||||
if (content is IDeactivated deactivated)
|
if (content is IDeactivated deactivated)
|
||||||
{
|
{
|
||||||
await deactivated.Deactivated();
|
await deactivated.OnDeactivated();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content is IDisposable disposable)
|
if (content is IDisposable disposable)
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
|
|||||||
{
|
{
|
||||||
if (content is IDeactivating deactivating)
|
if (content is IDeactivating deactivating)
|
||||||
{
|
{
|
||||||
await deactivating.Deactivating();
|
await deactivating.OnDeactivating();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,7 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
|
|||||||
{
|
{
|
||||||
if (content is IActivated activated)
|
if (content is IActivated activated)
|
||||||
{
|
{
|
||||||
await activated.Activated();
|
await activated.OnActivated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
|
|||||||
{
|
{
|
||||||
if (content is IDeactivated deactivated)
|
if (content is IDeactivated deactivated)
|
||||||
{
|
{
|
||||||
await deactivated.Deactivated();
|
await deactivated.OnDeactivated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class ContentTemplate :
|
|||||||
{
|
{
|
||||||
if (content is IActivated activated)
|
if (content is IActivated activated)
|
||||||
{
|
{
|
||||||
await activated.Activated();
|
await activated.OnActivated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ public class ContentTemplate :
|
|||||||
{
|
{
|
||||||
if (content is IActivated activated)
|
if (content is IActivated activated)
|
||||||
{
|
{
|
||||||
await activated.Activated();
|
await activated.OnActivated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ public class ContentTemplate :
|
|||||||
{
|
{
|
||||||
if (content is IDeactivated deactivated)
|
if (content is IDeactivated deactivated)
|
||||||
{
|
{
|
||||||
await deactivated.Deactivated();
|
await deactivated.OnDeactivated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class FrameHandler :
|
|||||||
{
|
{
|
||||||
if (content is IDeactivated deactivated)
|
if (content is IDeactivated deactivated)
|
||||||
{
|
{
|
||||||
await deactivated.Deactivated();
|
await deactivated.OnDeactivated();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content is not IKeepAlive)
|
if (content is not IKeepAlive)
|
||||||
@@ -63,7 +63,7 @@ public class FrameHandler :
|
|||||||
{
|
{
|
||||||
if (content is IDeactivating deactivating)
|
if (content is IDeactivating deactivating)
|
||||||
{
|
{
|
||||||
await deactivating.Deactivating();
|
await deactivating.OnDeactivating();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ public class FrameHandler :
|
|||||||
{
|
{
|
||||||
if (content is IActivated activated)
|
if (content is IActivated activated)
|
||||||
{
|
{
|
||||||
await activated.Activated();
|
await activated.OnActivated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ public class FrameHandler :
|
|||||||
{
|
{
|
||||||
if (content is IDeactivated deactivated)
|
if (content is IDeactivated deactivated)
|
||||||
{
|
{
|
||||||
await deactivated.Deactivated();
|
await deactivated.OnDeactivated();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content is IDisposable disposable)
|
if (content is IDisposable disposable)
|
||||||
|
|||||||
@@ -51,10 +51,10 @@ public partial class ComponentConfigurationViewModel<TConfiguration, TValue, TAc
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private object description = description;
|
private object description = description;
|
||||||
|
|
||||||
public override Task Activated()
|
public override Task OnActivated()
|
||||||
{
|
{
|
||||||
Value = valueDelegate.Invoke(configuration);
|
Value = valueDelegate.Invoke(configuration);
|
||||||
return base.Activated();
|
return base.OnActivated();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Handle(ChangedEventArgs<TConfiguration> args)
|
public Task Handle(ChangedEventArgs<TConfiguration> args)
|
||||||
@@ -93,10 +93,10 @@ public partial class ComponentConfigurationViewModel<TConfiguration, TValue, TDe
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private TDescription description = description;
|
private TDescription description = description;
|
||||||
|
|
||||||
public override Task Activated()
|
public override Task OnActivated()
|
||||||
{
|
{
|
||||||
Value = valueDelegate.Invoke(configuration);
|
Value = valueDelegate.Invoke(configuration);
|
||||||
return base.Activated();
|
return base.OnActivated();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Handle(ChangedEventArgs<TConfiguration> args)
|
public Task Handle(ChangedEventArgs<TConfiguration> args)
|
||||||
|
|||||||
@@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
public interface IActivated
|
public interface IActivated
|
||||||
{
|
{
|
||||||
Task Activated();
|
Task OnActivated();
|
||||||
}
|
}
|
||||||
@@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
public interface IDeactivated
|
public interface IDeactivated
|
||||||
{
|
{
|
||||||
Task Deactivated();
|
Task OnDeactivated();
|
||||||
}
|
}
|
||||||
@@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
public interface IDeactivating
|
public interface IDeactivating
|
||||||
{
|
{
|
||||||
Task Deactivating();
|
Task OnDeactivating();
|
||||||
}
|
}
|
||||||
@@ -24,6 +24,9 @@ public partial class Observable(IServiceProvider provider,
|
|||||||
{
|
{
|
||||||
private readonly Dictionary<string, object> trackedProperties = [];
|
private readonly Dictionary<string, object> trackedProperties = [];
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool isActivated;
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool isActive;
|
private bool isActive;
|
||||||
|
|
||||||
@@ -42,6 +45,12 @@ public partial class Observable(IServiceProvider provider,
|
|||||||
|
|
||||||
public ISubscriber Subscriber { get; } = subscriber;
|
public ISubscriber Subscriber { get; } = subscriber;
|
||||||
|
|
||||||
|
public virtual Task OnActivated()
|
||||||
|
{
|
||||||
|
IsActivated = true;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
public void Commit()
|
public void Commit()
|
||||||
{
|
{
|
||||||
foreach (object trackedProperty in trackedProperties.Values)
|
foreach (object trackedProperty in trackedProperties.Values)
|
||||||
@@ -50,6 +59,15 @@ public partial class Observable(IServiceProvider provider,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual Task OnDeactivated()
|
||||||
|
{
|
||||||
|
IsActivated = false;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual Task OnDeactivating() =>
|
||||||
|
Task.CompletedTask;
|
||||||
|
|
||||||
public virtual void Dispose()
|
public virtual void Dispose()
|
||||||
{
|
{
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
@@ -67,25 +85,6 @@ public partial class Observable(IServiceProvider provider,
|
|||||||
Subscriber.Subscribe(this);
|
Subscriber.Subscribe(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
[ObservableProperty]
|
|
||||||
private bool isActivated;
|
|
||||||
|
|
||||||
public virtual Task Activated()
|
|
||||||
{
|
|
||||||
IsActivated = true;
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public virtual Task Deactivated()
|
|
||||||
{
|
|
||||||
IsActivated = false;
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual Task Deactivating() =>
|
|
||||||
Task.CompletedTask;
|
|
||||||
|
|
||||||
public void Revert()
|
public void Revert()
|
||||||
{
|
{
|
||||||
foreach (object trackedProperty in trackedProperties.Values)
|
foreach (object trackedProperty in trackedProperties.Values)
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ public partial class ObservableCollection<TItem> :
|
|||||||
|
|
||||||
object? IList.this[int index]
|
object? IList.this[int index]
|
||||||
{
|
{
|
||||||
get => collection[index];
|
get => index >= 0 ? collection[index] : null;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
TItem? item = default;
|
TItem? item = default;
|
||||||
@@ -144,7 +144,7 @@ public partial class ObservableCollection<TItem> :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Task Activated()
|
public virtual Task OnActivated()
|
||||||
{
|
{
|
||||||
IsActivated = true;
|
IsActivated = true;
|
||||||
while (pendingEvents.Count > 0)
|
while (pendingEvents.Count > 0)
|
||||||
@@ -251,13 +251,13 @@ public partial class ObservableCollection<TItem> :
|
|||||||
void ICollection.CopyTo(Array array, int index) =>
|
void ICollection.CopyTo(Array array, int index) =>
|
||||||
collection.CopyTo((TItem[])array, index);
|
collection.CopyTo((TItem[])array, index);
|
||||||
|
|
||||||
public virtual Task Deactivated()
|
public virtual Task OnDeactivated()
|
||||||
{
|
{
|
||||||
IsActivated = false;
|
IsActivated = false;
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Task Deactivating() =>
|
public virtual Task OnDeactivating() =>
|
||||||
Task.CompletedTask;
|
Task.CompletedTask;
|
||||||
|
|
||||||
public virtual void Dispose()
|
public virtual void Dispose()
|
||||||
@@ -642,11 +642,15 @@ public partial class ObservableCollection<TItem> :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
partial void OnSelectedItemChanged(TItem? oldValue, TItem? newValue)
|
partial void OnSelectedItemChanged(TItem? oldValue, TItem? newValue)
|
||||||
{
|
{
|
||||||
if (oldValue is ISelectable oldSelection)
|
if (oldValue is ISelectable oldSelection)
|
||||||
{
|
{
|
||||||
oldSelection.IsSelected = false;
|
if (oldSelection.IsSelected)
|
||||||
|
{
|
||||||
|
oldSelection.IsSelected = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newValue is ISelectable newSelection)
|
if (newValue is ISelectable newSelection)
|
||||||
|
|||||||
@@ -1,8 +1,28 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
|
using Avalonia.Data.Converters;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
using Avalonia.Metadata;
|
using Avalonia.Metadata;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
namespace Toolkit.UI.Avalonia;
|
namespace Toolkit.UI.Avalonia;
|
||||||
|
|
||||||
|
public class NamedTypeConverter :
|
||||||
|
MarkupExtension,
|
||||||
|
IValueConverter
|
||||||
|
{
|
||||||
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
var d = value is not null ? value.GetType().Name : (object?)null;
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object ProvideValue(IServiceProvider serviceProvider) => this;
|
||||||
|
}
|
||||||
public class ConditionalExpression :
|
public class ConditionalExpression :
|
||||||
AvaloniaObject,
|
AvaloniaObject,
|
||||||
ICondition
|
ICondition
|
||||||
|
|||||||
@@ -14,6 +14,15 @@ public class InvokeNavigationViewItemAction :
|
|||||||
public static readonly StyledProperty<int> SelectedIndexProperty =
|
public static readonly StyledProperty<int> SelectedIndexProperty =
|
||||||
AvaloniaProperty.Register<InvokeNavigationViewItemAction, int>(nameof(SelectedIndex), 0);
|
AvaloniaProperty.Register<InvokeNavigationViewItemAction, int>(nameof(SelectedIndex), 0);
|
||||||
|
|
||||||
|
public static readonly StyledProperty<object> TargetProperty =
|
||||||
|
AvaloniaProperty.Register<InvokeNavigationViewItemAction, object>(nameof(Target));
|
||||||
|
|
||||||
|
public object Target
|
||||||
|
{
|
||||||
|
get => GetValue(TargetProperty);
|
||||||
|
set => SetValue(TargetProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
public int SelectedIndex
|
public int SelectedIndex
|
||||||
{
|
{
|
||||||
get => GetValue(SelectedIndexProperty);
|
get => GetValue(SelectedIndexProperty);
|
||||||
@@ -22,7 +31,7 @@ public class InvokeNavigationViewItemAction :
|
|||||||
|
|
||||||
public object? Execute(object? sender, object? parameter)
|
public object? Execute(object? sender, object? parameter)
|
||||||
{
|
{
|
||||||
if (sender is NavigationViewItem navigationViewItem)
|
if ((Target ?? sender) is NavigationViewItem navigationViewItem)
|
||||||
{
|
{
|
||||||
Dispatcher.UIThread.Post(() =>
|
Dispatcher.UIThread.Post(() =>
|
||||||
{
|
{
|
||||||
@@ -36,7 +45,7 @@ public class InvokeNavigationViewItemAction :
|
|||||||
}, DispatcherPriority.ContextIdle);
|
}, DispatcherPriority.ContextIdle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender is NavigationView navigationView)
|
if ((Target ?? sender) is NavigationView navigationView)
|
||||||
{
|
{
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
{
|
{
|
||||||
@@ -44,13 +53,12 @@ public class InvokeNavigationViewItemAction :
|
|||||||
{
|
{
|
||||||
if (collection is { Count: > 0 })
|
if (collection is { Count: > 0 })
|
||||||
{
|
{
|
||||||
if (collection[SelectedIndex] is ISelectable selectable)
|
|
||||||
{
|
|
||||||
selectable.IsSelected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
navigationView.SetValue(NavigationView.SelectedItemProperty, collection[SelectedIndex]);
|
navigationView.SetValue(NavigationView.SelectedItemProperty, collection[SelectedIndex]);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
navigationView.SetValue(NavigationView.SelectedItemProperty, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, DispatcherPriority.ContextIdle);
|
}, DispatcherPriority.ContextIdle);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@ public class NavigationViewExtension
|
|||||||
sender.RaiseEvent(new ItemInvokedEventArgs { RoutedEvent = ItemInvokedEvent });
|
sender.RaiseEvent(new ItemInvokedEventArgs { RoutedEvent = ItemInvokedEvent });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
navigationView.ItemInvoked += OnItemInvoked;
|
navigationView.ItemInvoked += OnItemInvoked;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user