Browse Source

Move dynamic name binding to static instead

pull/495/head
Ionite 9 months ago
parent
commit
7c746138e3
No known key found for this signature in database
  1. 2
      StabilityMatrix.Avalonia/Controls/AdvancedImageBoxView.axaml
  2. 15
      StabilityMatrix.Avalonia/Controls/AdvancedImageBoxView.axaml.cs

2
StabilityMatrix.Avalonia/Controls/AdvancedImageBoxView.axaml

@ -35,7 +35,7 @@
<controls:AdvancedImageBox.ContextFlyout> <controls:AdvancedImageBox.ContextFlyout>
<ui:FAMenuFlyout> <ui:FAMenuFlyout>
<ui:MenuFlyoutItem <ui:MenuFlyoutItem
x:Name="CopyMenuItem" Command="{x:Static controls:AdvancedImageBoxView.FlyoutCopyCommand}"
CommandParameter="{Binding $parent[controls:AdvancedImageBox].Image}" CommandParameter="{Binding $parent[controls:AdvancedImageBox].Image}"
HotKey="Ctrl+C" HotKey="Ctrl+C"
IconSource="Copy" IconSource="Copy"

15
StabilityMatrix.Avalonia/Controls/AdvancedImageBoxView.axaml.cs

@ -1,9 +1,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Media.Imaging; using Avalonia.Media.Imaging;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
using FluentAvalonia.UI.Controls;
using StabilityMatrix.Avalonia.Helpers; using StabilityMatrix.Avalonia.Helpers;
using StabilityMatrix.Core.Helper; using StabilityMatrix.Core.Helper;
@ -16,18 +14,9 @@ public partial class AdvancedImageBoxView : UserControl
InitializeComponent(); InitializeComponent();
} }
/// <inheritdoc /> public static AsyncRelayCommand<Bitmap?> FlyoutCopyCommand { get; } = new(FlyoutCopy);
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
if (this.FindControl<MenuFlyoutItem>("CopyMenuItem") is { } copyMenuItem)
{
copyMenuItem.Command = new AsyncRelayCommand<Bitmap?>(FlyoutCopy);
}
}
private static async Task FlyoutCopy(Bitmap? image) public static async Task FlyoutCopy(Bitmap? image)
{ {
if (image is null || !Compat.IsWindows) if (image is null || !Compat.IsWindows)
return; return;

Loading…
Cancel
Save