From 7145201077aa6bb51117d59fa4f6dfa7018417af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=8A=BC?= Date: Tue, 16 Sep 2025 14:04:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=BC=BA=20OverlayDialog=20?= =?UTF-8?q?=E5=92=8C=20NumPad=20=E7=9A=84=E5=8A=9F=E8=83=BD=E4=B8=8E?= =?UTF-8?q?=E4=BA=A4=E4=BA=92=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 OverlayDialogOptions.OnDialogControlClosed 委托属性, 支持自定义对话框关闭事件处理逻辑,并在 OverlayDialog 中 添加了相关事件绑定与解绑逻辑。 调整 NumPad 的显示与交互逻辑,确保在数字键盘关闭后, 目标输入控件能够重新获取焦点,优化用户体验。 --- .../Dialog/Options/OverlayDialogOptions.cs | 4 ++++ src/Ursa/Controls/Dialog/OverlayDialog.cs | 14 +++++++++++++- src/Ursa/Controls/NumPad/NumPad.cs | 15 +++++++++++---- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Ursa/Controls/Dialog/Options/OverlayDialogOptions.cs b/src/Ursa/Controls/Dialog/Options/OverlayDialogOptions.cs index 086fc32..0ed136d 100644 --- a/src/Ursa/Controls/Dialog/Options/OverlayDialogOptions.cs +++ b/src/Ursa/Controls/Dialog/Options/OverlayDialogOptions.cs @@ -66,4 +66,8 @@ public class OverlayDialogOptions public bool CanResize { get; set; } public string? StyleClass { get; set; } + + /// + /// + internal Delegate? OnDialogControlClosed { set; get; } } \ No newline at end of file diff --git a/src/Ursa/Controls/Dialog/OverlayDialog.cs b/src/Ursa/Controls/Dialog/OverlayDialog.cs index bc6e01a..beb78f1 100644 --- a/src/Ursa/Controls/Dialog/OverlayDialog.cs +++ b/src/Ursa/Controls/Dialog/OverlayDialog.cs @@ -34,10 +34,22 @@ public static class OverlayDialog DataContext = vm, }; ConfigureDefaultDialogControl(t, options); + + if (options?.OnDialogControlClosed != null) + { + t.AddHandler(OverlayShared.OverlayFeedbackElement.ClosedEvent, options.OnDialogControlClosed); + + t.AddHandler(OverlayShared.OverlayFeedbackElement.ClosedEvent, (s,e)=> + { + if (s is not DialogControlBase control) return; + control.RemoveHandler(OverlayShared.OverlayFeedbackElement.ClosedEvent, options.OnDialogControlClosed); + }); + } + host.AddDialog(t); } - + public static void Show(object? vm, string? hostId = null, OverlayDialogOptions? options = null) { var host = OverlayDialogManager.GetHost(hostId, options?.TopLevelHashCode); diff --git a/src/Ursa/Controls/NumPad/NumPad.cs b/src/Ursa/Controls/NumPad/NumPad.cs index 45228ea..5c9d5cc 100644 --- a/src/Ursa/Controls/NumPad/NumPad.cs +++ b/src/Ursa/Controls/NumPad/NumPad.cs @@ -55,7 +55,7 @@ public class NumPad: TemplatedControl GotFocusEvent.RemoveHandler(OnTargetGotFocus, input); } } - + private static void OnTargetGotFocus(object? sender, GotFocusEventArgs e) { if (sender is not InputElement) return; @@ -75,12 +75,19 @@ public class NumPad: TemplatedControl } return; } - var numPad = new NumPad() + var numPad = new NumPad() { Target = sender as InputElement , _targetInnerText = FindTextBoxInTarget((sender as InputElement)!) }; - OverlayDialog.Show(numPad, new object(), options: new OverlayDialogOptions() { Buttons = DialogButton.None }); + OverlayDialog.Show(numPad, new object(), options: new OverlayDialogOptions() + { + Buttons = DialogButton.None, + OnDialogControlClosed = (object? ss, object? e) => + { + numPad.Target?.Focus(); + } + }); } private static readonly Dictionary KeyInputMapping = new() @@ -138,7 +145,7 @@ public class NumPad: TemplatedControl // 如果目标本身就是 TextBox if (target is TextBox textBox) return textBox; - + // 如果目标是 TemplatedControl,并且已经应用了模板 if (target is TemplatedControl templatedControl && templatedControl.IsInitialized) { From baefa8c6eb3e7dd781ff69e4bcd8d0da331cee66 Mon Sep 17 00:00:00 2001 From: Dong Bin Date: Fri, 19 Sep 2025 18:12:42 +0800 Subject: [PATCH 2/2] fix: fix naming. --- src/Ursa/Controls/Dialog/OverlayDialog.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Ursa/Controls/Dialog/OverlayDialog.cs b/src/Ursa/Controls/Dialog/OverlayDialog.cs index beb78f1..08f94a5 100644 --- a/src/Ursa/Controls/Dialog/OverlayDialog.cs +++ b/src/Ursa/Controls/Dialog/OverlayDialog.cs @@ -39,10 +39,10 @@ public static class OverlayDialog { t.AddHandler(OverlayShared.OverlayFeedbackElement.ClosedEvent, options.OnDialogControlClosed); - t.AddHandler(OverlayShared.OverlayFeedbackElement.ClosedEvent, (s,e)=> + t.AddHandler(OverlayShared.OverlayFeedbackElement.ClosedEvent, (s, _) => { - if (s is not DialogControlBase control) return; - control.RemoveHandler(OverlayShared.OverlayFeedbackElement.ClosedEvent, options.OnDialogControlClosed); + if (s is not DialogControlBase dc) return; + dc.RemoveHandler(OverlayShared.OverlayFeedbackElement.ClosedEvent, options.OnDialogControlClosed); }); }