Codemaid
This commit is contained in:
@@ -9,4 +9,4 @@ public class AttachedBehaviour : Trigger
|
||||
Interaction.ExecuteActions(AssociatedObject, Actions, null);
|
||||
base.OnAttachedToVisualTree();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,14 +21,13 @@ public class AttachedEventTriggerBehaviour : Trigger
|
||||
{
|
||||
if (AssociatedObject is Interactive interactive)
|
||||
{
|
||||
interactive.AddHandler(RoutedEvent, (object sender, RoutedEventArgs args) => {
|
||||
|
||||
interactive.AddHandler(RoutedEvent, (object sender, RoutedEventArgs args) =>
|
||||
{
|
||||
Interaction.ExecuteActions(AssociatedObject, Actions, null);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
base.OnAttached();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,4 +43,4 @@ public class InvokeNavigationViewItemAction :
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
namespace Toolkit.UI.Avalonia;
|
||||
|
||||
public class ItemInvokedEventArgs :
|
||||
public class ItemInvokedEventArgs :
|
||||
RoutedEventArgs
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -21,19 +21,20 @@ public class NavigateRegionAction :
|
||||
|
||||
[Content]
|
||||
public ActionCollection Actions => actions ??= [];
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => GetValue(NameProperty);
|
||||
set => SetValue(NameProperty, value);
|
||||
}
|
||||
|
||||
public object? Execute(object? sender,
|
||||
public object? Execute(object? sender,
|
||||
object? parameter)
|
||||
{
|
||||
if (sender is Control control)
|
||||
{
|
||||
if (control.DataContext is IObservableViewModel observableViewModel)
|
||||
{
|
||||
{
|
||||
if (observableViewModel.Provider.GetRequiredService<INavigationRegion>() is INavigationRegion navigationRegion)
|
||||
{
|
||||
navigationRegion.Register(Name, sender);
|
||||
@@ -44,4 +45,4 @@ public class NavigateRegionAction :
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,8 @@ public class NavigationViewItemExtension
|
||||
AvaloniaProperty.RegisterAttached<NavigationViewItem, bool>("IsItemClickEnabled",
|
||||
typeof(NavigationViewItemExtension), false);
|
||||
|
||||
public static readonly RoutedEvent<ItemInvokedEventArgs> ItemClickEvent =
|
||||
RoutedEvent.Register<ItemInvokedEventArgs>("ItemClick",
|
||||
public static readonly RoutedEvent<ItemInvokedEventArgs> ItemClickEvent =
|
||||
RoutedEvent.Register<ItemInvokedEventArgs>("ItemClick",
|
||||
RoutingStrategies.Bubble, typeof(NavigationViewItemExtension));
|
||||
|
||||
static NavigationViewItemExtension()
|
||||
@@ -20,7 +20,7 @@ public class NavigationViewItemExtension
|
||||
IsItemClickEnabledProperty.Changed.AddClassHandler<NavigationViewItem>(OnIsItemClickEnabledPropertyChanged);
|
||||
}
|
||||
|
||||
private static void OnIsItemClickEnabledPropertyChanged(NavigationViewItem sender,
|
||||
private static void OnIsItemClickEnabledPropertyChanged(NavigationViewItem sender,
|
||||
AvaloniaPropertyChangedEventArgs args)
|
||||
{
|
||||
bool TrySetupNavigationView()
|
||||
@@ -43,7 +43,7 @@ public class NavigationViewItemExtension
|
||||
}
|
||||
|
||||
if (!TrySetupNavigationView())
|
||||
{
|
||||
{
|
||||
void OnAttachedToVisualTree(object? _, VisualTreeAttachmentEventArgs __)
|
||||
{
|
||||
sender.AttachedToVisualTree -= OnAttachedToVisualTree;
|
||||
@@ -57,12 +57,12 @@ public class NavigationViewItemExtension
|
||||
public static bool GetIsItemClickEnabled(NavigationViewItem element) =>
|
||||
element.GetValue(IsItemClickEnabledProperty);
|
||||
|
||||
public static void SetIsItemClickEnabled(NavigationViewItem element, bool value) =>
|
||||
public static void SetIsItemClickEnabled(NavigationViewItem element, bool value) =>
|
||||
element.SetValue(IsItemClickEnabledProperty, value);
|
||||
|
||||
public static void AddItemClickHandler(NavigationViewItem element, EventHandler<ItemInvokedEventArgs> handler) =>
|
||||
public static void AddItemClickHandler(NavigationViewItem element, EventHandler<ItemInvokedEventArgs> handler) =>
|
||||
element.AddHandler(ItemClickEvent, handler);
|
||||
|
||||
public static void RemoveItemClickHandler(NavigationViewItem element, EventHandler<ItemInvokedEventArgs> handler) =>
|
||||
element.RemoveHandler(ItemClickEvent, handler);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user