UI
This commit is contained in:
@@ -9,3 +9,8 @@ public interface IProvider<TService>
|
|||||||
{
|
{
|
||||||
TService? Get();
|
TService? Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface ISelectable
|
||||||
|
{
|
||||||
|
bool Selected { get; set; }
|
||||||
|
}
|
||||||
@@ -97,7 +97,7 @@ public partial class ObservableCollectionViewModel<TViewModel> :
|
|||||||
|
|
||||||
public TViewModel this[int index]
|
public TViewModel this[int index]
|
||||||
{
|
{
|
||||||
get => collection[index];
|
get => Count > 0 ? collection[index] : default;
|
||||||
set => SetItem(index, value);
|
set => SetItem(index, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Toolkit.UI.Avalonia;
|
namespace Toolkit.UI.Avalonia;
|
||||||
|
|
||||||
public class AttachedBehavior : Trigger
|
public class AttachedBehaviour : Trigger
|
||||||
{
|
{
|
||||||
protected override void OnAttachedToVisualTree()
|
protected override void OnAttachedToVisualTree()
|
||||||
{
|
{
|
||||||
+3
-3
@@ -5,12 +5,12 @@ using System.Windows.Input;
|
|||||||
|
|
||||||
namespace Toolkit.UI.Avalonia;
|
namespace Toolkit.UI.Avalonia;
|
||||||
|
|
||||||
public class KeyBindingTriggerBehavior :
|
public class KeyBindingTriggerBehaviour :
|
||||||
Trigger<InputElement>,
|
Trigger<InputElement>,
|
||||||
ICommand
|
ICommand
|
||||||
{
|
{
|
||||||
public static readonly StyledProperty<KeyGesture> GestureProperty =
|
public static readonly StyledProperty<KeyGesture> GestureProperty =
|
||||||
AvaloniaProperty.Register<KeyBindingTriggerBehavior, KeyGesture>(nameof(Gesture));
|
AvaloniaProperty.Register<KeyBindingTriggerBehaviour, KeyGesture>(nameof(Gesture));
|
||||||
|
|
||||||
public KeyGesture Gesture
|
public KeyGesture Gesture
|
||||||
{
|
{
|
||||||
@@ -24,7 +24,7 @@ public class KeyBindingTriggerBehavior :
|
|||||||
{
|
{
|
||||||
if (Gesture is not null)
|
if (Gesture is not null)
|
||||||
{
|
{
|
||||||
KeyBinding keyBinding = new KeyBinding
|
KeyBinding keyBinding = new()
|
||||||
{
|
{
|
||||||
Gesture = Gesture,
|
Gesture = Gesture,
|
||||||
Command = this
|
Command = this
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.VisualTree;
|
||||||
|
using Avalonia.Xaml.Interactivity;
|
||||||
|
using FluentAvalonia.Core;
|
||||||
|
using System.Collections;
|
||||||
|
using Toolkit.UI.Controls.Avalonia;
|
||||||
|
using ISelectable = Toolkit.Foundation.ISelectable;
|
||||||
|
|
||||||
|
namespace Toolkit.UI.Avalonia;
|
||||||
|
|
||||||
|
public class NavigationViewItemInvokedBehaviour : Trigger
|
||||||
|
{
|
||||||
|
public static readonly StyledProperty<bool> SelectsChildOnInvokedProperty =
|
||||||
|
AvaloniaProperty.Register<NavigationViewItemInvokedBehaviour, bool>(nameof(SelectsChildOnInvoked));
|
||||||
|
|
||||||
|
private NavigationView? navigationView;
|
||||||
|
|
||||||
|
public event TypedEventHandler<NavigationViewItem, EventArgs>? Invoked;
|
||||||
|
|
||||||
|
public bool SelectsChildOnInvoked
|
||||||
|
{
|
||||||
|
get => GetValue(SelectsChildOnInvokedProperty);
|
||||||
|
set => SetValue(SelectsChildOnInvokedProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnAttached()
|
||||||
|
{
|
||||||
|
if (AssociatedObject is NavigationViewItem navigationViewItem)
|
||||||
|
{
|
||||||
|
navigationViewItem.AttachedToVisualTree += OnAttachedToVisualTree;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.OnAttached();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnDetachedFromVisualTree()
|
||||||
|
{
|
||||||
|
if (navigationView is not null)
|
||||||
|
{
|
||||||
|
navigationView.ItemInvoked -= OnItemInvoked;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.OnDetachedFromVisualTree();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnAttachedToVisualTree(object? sender,
|
||||||
|
VisualTreeAttachmentEventArgs args)
|
||||||
|
{
|
||||||
|
if (AssociatedObject is NavigationViewItem navigationViewItem)
|
||||||
|
{
|
||||||
|
navigationViewItem.AttachedToVisualTree -= OnAttachedToVisualTree;
|
||||||
|
SetupNavigationView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnItemInvoked(object? sender,
|
||||||
|
FluentAvalonia.UI.Controls.NavigationViewItemInvokedEventArgs args)
|
||||||
|
{
|
||||||
|
if (AssociatedObject is NavigationViewItem navigationViewItem)
|
||||||
|
{
|
||||||
|
if (args.InvokedItemContainer == AssociatedObject)
|
||||||
|
{
|
||||||
|
Interaction.ExecuteActions(AssociatedObject, Actions, null);
|
||||||
|
if (!navigationViewItem.IsChildSelected && navigationViewItem.MenuItemsSource is IList collection)
|
||||||
|
{
|
||||||
|
if (collection is { Count: > 0 } && collection[0] is ISelectable selectable)
|
||||||
|
{
|
||||||
|
selectable.Selected = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupNavigationView()
|
||||||
|
{
|
||||||
|
if (AssociatedObject is NavigationViewItem navigationViewItem)
|
||||||
|
{
|
||||||
|
if (navigationViewItem.GetVisualAncestors().OfType<NavigationView>().FirstOrDefault() is NavigationView navigationView)
|
||||||
|
{
|
||||||
|
this.navigationView = navigationView;
|
||||||
|
navigationView.ItemInvoked += OnItemInvoked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,5 +10,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Toolkit.Foundation\Toolkit.Foundation.csproj" />
|
<ProjectReference Include="..\Toolkit.Foundation\Toolkit.Foundation.csproj" />
|
||||||
|
<ProjectReference Include="..\Toolkit.UI.Controls.Avalonia\Toolkit.UI.Controls.Avalonia.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user