Add vault content navigation
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia" Version="11.1.0-beta2" />
|
<PackageReference Include="Avalonia" Version="11.2.999-cibuild0048140-alpha" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Toolkit.Foundation\Toolkit.Foundation.csproj" />
|
<ProjectReference Include="..\Toolkit.Foundation\Toolkit.Foundation.csproj" />
|
||||||
|
|||||||
@@ -1,86 +1,10 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.LogicalTree;
|
using Avalonia.LogicalTree;
|
||||||
using Toolkit.UI.Controls.Avalonia;
|
using Toolkit.UI.Controls.Avalonia;
|
||||||
|
|
||||||
namespace Toolkit.UI.Avalonia;
|
namespace Toolkit.UI.Avalonia;
|
||||||
|
|
||||||
public class ListBoxItemExtension
|
|
||||||
{
|
|
||||||
public static readonly AttachedProperty<bool> IsItemClickEnabledProperty =
|
|
||||||
AvaloniaProperty.RegisterAttached<ListBoxItem, bool>("IsItemClickEnabled",
|
|
||||||
typeof(ListBoxItemExtension), false);
|
|
||||||
|
|
||||||
public static readonly RoutedEvent<ItemInvokedEventArgs> ItemClickEvent =
|
|
||||||
RoutedEvent.Register<ItemInvokedEventArgs>("ItemClick",
|
|
||||||
RoutingStrategies.Bubble, typeof(ListBoxItemExtension));
|
|
||||||
|
|
||||||
static ListBoxItemExtension()
|
|
||||||
{
|
|
||||||
IsItemClickEnabledProperty.Changed.AddClassHandler<ListBoxItem>(OnIsItemClickEnabledPropertyChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OnIsItemClickEnabledPropertyChanged(ListBoxItem sender,
|
|
||||||
AvaloniaPropertyChangedEventArgs args)
|
|
||||||
{
|
|
||||||
bool TrySetupListBox()
|
|
||||||
{
|
|
||||||
if (sender.GetLogicalAncestors().OfType<ListBox>().FirstOrDefault() is ListBox listBox)
|
|
||||||
{
|
|
||||||
void OnItemInvoked(object? _, FluentAvalonia.UI.Controls.NavigationViewItemInvokedEventArgs args)
|
|
||||||
{
|
|
||||||
if (args.InvokedItemContainer == sender)
|
|
||||||
{
|
|
||||||
sender.RaiseEvent(new ItemInvokedEventArgs { RoutedEvent = ItemClickEvent });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnSelectionChanged(object? sender, SelectionChangedEventArgs args)
|
|
||||||
{
|
|
||||||
foreach (object item in args.AddedItems)
|
|
||||||
{
|
|
||||||
if (listBox.ContainerFromItem(item) == sender)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
listBox.SelectionChanged += OnSelectionChanged;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TrySetupListBox())
|
|
||||||
{
|
|
||||||
void OnAttachedToVisualTree(object? _, VisualTreeAttachmentEventArgs __)
|
|
||||||
{
|
|
||||||
sender.AttachedToVisualTree -= OnAttachedToVisualTree;
|
|
||||||
TrySetupListBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.AttachedToVisualTree += OnAttachedToVisualTree;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool GetIsItemClickEnabled(ListBoxItem element) =>
|
|
||||||
element.GetValue(IsItemClickEnabledProperty);
|
|
||||||
|
|
||||||
public static void SetIsItemClickEnabled(ListBoxItem element, bool value) =>
|
|
||||||
element.SetValue(IsItemClickEnabledProperty, value);
|
|
||||||
|
|
||||||
public static void AddItemClickHandler(ListBoxItem element, EventHandler<ItemInvokedEventArgs> handler) =>
|
|
||||||
element.AddHandler(ItemClickEvent, handler);
|
|
||||||
|
|
||||||
public static void RemoveItemClickHandler(ListBoxItem element, EventHandler<ItemInvokedEventArgs> handler) =>
|
|
||||||
element.RemoveHandler(ItemClickEvent, handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public class NavigationViewItemExtension
|
public class NavigationViewItemExtension
|
||||||
{
|
{
|
||||||
public static readonly AttachedProperty<bool> IsItemClickEnabledProperty =
|
public static readonly AttachedProperty<bool> IsItemClickEnabledProperty =
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia" Version="11.1.0-beta2" />
|
<PackageReference Include="Avalonia" Version="11.2.999-cibuild0048140-alpha" />
|
||||||
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.1.0-beta2.1" />
|
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.1.0-beta2.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia" Version="11.1.0-beta2" />
|
<PackageReference Include="Avalonia" Version="11.2.999-cibuild0048140-alpha" />
|
||||||
<PackageReference Include="Avalonia.Labs.Controls" Version="11.0.10.1" />
|
<PackageReference Include="Avalonia.Labs.Controls" Version="11.0.10.1" />
|
||||||
<PackageReference Include="FluentAvaloniaUI" Version="2.1.0-preview1" />
|
<PackageReference Include="FluentAvaloniaUI" Version="2.1.0-preview1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user