From b11144891aacfb2976057ee3ed8906028a028aae Mon Sep 17 00:00:00 2001 From: Tongg Date: Mon, 13 Jan 2025 10:57:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B6=88=E6=81=AF=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=8C=E8=BE=93=E5=85=A5=E6=A1=86=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=8E=B7=E7=84=A6=EF=BC=8C=E5=9B=9E=E8=BD=A6=E7=A1=AE?= =?UTF-8?q?=E8=AE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Views/Dialog/MessageBox.xaml.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Views/Dialog/MessageBox.xaml.cs b/Views/Dialog/MessageBox.xaml.cs index 6ad6bf1..6c167bb 100644 --- a/Views/Dialog/MessageBox.xaml.cs +++ b/Views/Dialog/MessageBox.xaml.cs @@ -69,11 +69,17 @@ public partial class MessageBox : Window return _result; } // - public MessageBoxResult ShowInput(String message, out String inputStr , String confirmButtonTitle = "", String cancelButtonTitle ="") + public MessageBoxResult ShowInput(String message, out String inputStr , String confirmButtonTitle = "", String cancelButtonTitle ="", bool EnterConfirm = true) { _showType = 2; this.Height = 300; TextBlockCenterBox.Text = message; + TextBoxInput.Focus(); + if (EnterConfirm) + { + TextBoxInput.KeyDown += TextBoxInput_OnKeyDown; + } + if (!string.IsNullOrWhiteSpace(confirmButtonTitle) && !string.IsNullOrWhiteSpace(cancelButtonTitle)) { ConfirmButtonText.Text = confirmButtonTitle; @@ -136,4 +142,12 @@ public partial class MessageBox : Window } } + + private void TextBoxInput_OnKeyDown(object sender, KeyEventArgs e) + { + if (e.Key == Key.Enter) // 检测是否按下回车键 + { + ConfirmButton_OnClick(sender, e); // 调用按钮的点击事件 + } + } } \ No newline at end of file