fixes
This commit is contained in:
@@ -1,8 +1,28 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Data.Converters;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Metadata;
|
||||
using System.Globalization;
|
||||
|
||||
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 :
|
||||
AvaloniaObject,
|
||||
ICondition
|
||||
|
||||
@@ -14,6 +14,15 @@ public class InvokeNavigationViewItemAction :
|
||||
public static readonly StyledProperty<int> SelectedIndexProperty =
|
||||
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
|
||||
{
|
||||
get => GetValue(SelectedIndexProperty);
|
||||
@@ -22,7 +31,7 @@ public class InvokeNavigationViewItemAction :
|
||||
|
||||
public object? Execute(object? sender, object? parameter)
|
||||
{
|
||||
if (sender is NavigationViewItem navigationViewItem)
|
||||
if ((Target ?? sender) is NavigationViewItem navigationViewItem)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
@@ -36,7 +45,7 @@ public class InvokeNavigationViewItemAction :
|
||||
}, DispatcherPriority.ContextIdle);
|
||||
}
|
||||
|
||||
if (sender is NavigationView navigationView)
|
||||
if ((Target ?? sender) is NavigationView navigationView)
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
@@ -44,13 +53,12 @@ public class InvokeNavigationViewItemAction :
|
||||
{
|
||||
if (collection is { Count: > 0 })
|
||||
{
|
||||
if (collection[SelectedIndex] is ISelectable selectable)
|
||||
{
|
||||
selectable.IsSelected = true;
|
||||
}
|
||||
|
||||
navigationView.SetValue(NavigationView.SelectedItemProperty, collection[SelectedIndex]);
|
||||
}
|
||||
else
|
||||
{
|
||||
navigationView.SetValue(NavigationView.SelectedItemProperty, null);
|
||||
}
|
||||
}
|
||||
}, DispatcherPriority.ContextIdle);
|
||||
}
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ public class NavigationViewExtension
|
||||
sender.RaiseEvent(new ItemInvokedEventArgs { RoutedEvent = ItemInvokedEvent });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
navigationView.ItemInvoked += OnItemInvoked;
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user