49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using Avalonia;
|
|
using Avalonia.Threading;
|
|
using Avalonia.Xaml.Interactivity;
|
|
using System.Collections;
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.Specialized;
|
|
using Toolkit.Foundation;
|
|
using Toolkit.UI.Controls.Avalonia;
|
|
|
|
namespace Toolkit.UI.Avalonia;
|
|
|
|
public class SelectNavigationViewItemAction :
|
|
AvaloniaObject,
|
|
IAction
|
|
{
|
|
public object? Execute(object? sender, object? parameter)
|
|
{
|
|
if (sender is NavigationViewItem navigationViewItem)
|
|
{
|
|
Dispatcher.UIThread.Post(() =>
|
|
{
|
|
if (navigationViewItem.MenuItemsSource is IList collection)
|
|
{
|
|
if (collection is { Count: > 0 } && collection[0] is ISelectable selectable)
|
|
{
|
|
selectable.Selected = true;
|
|
}
|
|
}
|
|
}, DispatcherPriority.ContextIdle);
|
|
}
|
|
|
|
if (sender is NavigationView navigationView)
|
|
{
|
|
Dispatcher.UIThread.Post(() =>
|
|
{
|
|
if (navigationView.MenuItemsSource is IList collection)
|
|
{
|
|
if (collection is { Count: > 0 } && collection[0] is ISelectable selectable)
|
|
{
|
|
selectable.Selected = true;
|
|
}
|
|
}
|
|
}, DispatcherPriority.ContextIdle);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|