From c1d486297d78ac6712bbe6bf5eaadf8f64e69863 Mon Sep 17 00:00:00 2001 From: Dong Bin Date: Fri, 18 Apr 2025 00:43:37 +0800 Subject: [PATCH] feat: add popconfirm. --- src/Ursa/Controls/PopConfirm/PopConfirm.cs | 125 ++++++++++++++++++ .../PopConfirm/PopConfirmTriggerMode.cs | 8 ++ 2 files changed, 133 insertions(+) create mode 100644 src/Ursa/Controls/PopConfirm/PopConfirm.cs create mode 100644 src/Ursa/Controls/PopConfirm/PopConfirmTriggerMode.cs diff --git a/src/Ursa/Controls/PopConfirm/PopConfirm.cs b/src/Ursa/Controls/PopConfirm/PopConfirm.cs new file mode 100644 index 0000000..f0096ca --- /dev/null +++ b/src/Ursa/Controls/PopConfirm/PopConfirm.cs @@ -0,0 +1,125 @@ +using System.Windows.Input; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.Presenters; +using Avalonia.Controls.Primitives; +using Avalonia.Controls.Templates; + +namespace Ursa.Controls; + +public class PopConfirm: ContentControl +{ + public static readonly StyledProperty PopupHeaderProperty = AvaloniaProperty.Register( + nameof(PopupHeader)); + + public object? PopupHeader + { + get => GetValue(PopupHeaderProperty); + set => SetValue(PopupHeaderProperty, value); + } + + public static readonly StyledProperty PopupHeaderTemplateProperty = AvaloniaProperty.Register( + nameof(PopupHeaderTemplate)); + + public IDataTemplate? PopupHeaderTemplate + { + get => GetValue(PopupHeaderTemplateProperty); + set => SetValue(PopupHeaderTemplateProperty, value); + } + + public static readonly StyledProperty PopupContentProperty = AvaloniaProperty.Register( + nameof(PopupContent)); + + public object? PopupContent + { + get => GetValue(PopupContentProperty); + set => SetValue(PopupContentProperty, value); + } + + public static readonly StyledProperty PopupContentTemplateProperty = AvaloniaProperty.Register( + nameof(PopupContentTemplate)); + + public IDataTemplate? PopupContentTemplate + { + get => GetValue(PopupContentTemplateProperty); + set => SetValue(PopupContentTemplateProperty, value); + } + + public static readonly StyledProperty ConfirmCommandProperty = AvaloniaProperty.Register( + nameof(ConfirmCommand)); + + public ICommand? ConfirmCommand + { + get => GetValue(ConfirmCommandProperty); + set => SetValue(ConfirmCommandProperty, value); + } + + public static readonly StyledProperty CancelCommandProperty = AvaloniaProperty.Register( + nameof(CancelCommand)); + + public ICommand? CancelCommand + { + get => GetValue(CancelCommandProperty); + set => SetValue(CancelCommandProperty, value); + } + + public static readonly StyledProperty ConfirmCommandParameterProperty = AvaloniaProperty.Register( + nameof(ConfirmCommandParameter)); + + public object? ConfirmCommandParameter + { + get => GetValue(ConfirmCommandParameterProperty); + set => SetValue(ConfirmCommandParameterProperty, value); + } + + public static readonly StyledProperty CancelCommandParameterProperty = AvaloniaProperty.Register( + nameof(CancelCommandParameter)); + + public object? CancelCommandParameter + { + get => GetValue(CancelCommandParameterProperty); + set => SetValue(CancelCommandParameterProperty, value); + } + + public static readonly StyledProperty TriggerModeProperty = + AvaloniaProperty.Register( + nameof(TriggerMode)); + + public PopConfirmTriggerMode TriggerMode + { + get => GetValue(TriggerModeProperty); + set => SetValue(TriggerModeProperty, value); + } + + static PopConfirm() + { + ConfirmCommandProperty.Changed.AddClassHandler((popconfirm, args) => popconfirm.OnCommandChanged(args)); + } + + private void OnCommandChanged(AvaloniaPropertyChangedEventArgs args) + { + var newValue = args.GetNewValue(); + newValue.CanExecuteChanged += (sender, e) => + { + if (args.Sender is PopConfirm popconfirm) + { + var b = newValue.CanExecute(this.ConfirmCommandParameter); + } + }; + } + + public PopConfirm() + { + + } + + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) + { + base.OnApplyTemplate(e); + } + + protected override bool RegisterContentPresenter(ContentPresenter presenter) + { + return base.RegisterContentPresenter(presenter); + } +} \ No newline at end of file diff --git a/src/Ursa/Controls/PopConfirm/PopConfirmTriggerMode.cs b/src/Ursa/Controls/PopConfirm/PopConfirmTriggerMode.cs new file mode 100644 index 0000000..09113a5 --- /dev/null +++ b/src/Ursa/Controls/PopConfirm/PopConfirmTriggerMode.cs @@ -0,0 +1,8 @@ +namespace Ursa.Controls; + +public enum PopConfirmTriggerMode +{ + Tap, + Hover, + Focus, +} \ No newline at end of file