diff --git a/src/MeoAsstGui/ViewModels/CopilotViewModel.cs b/src/MeoAsstGui/ViewModels/CopilotViewModel.cs index 3fded122d3..d272e1bec3 100644 --- a/src/MeoAsstGui/ViewModels/CopilotViewModel.cs +++ b/src/MeoAsstGui/ViewModels/CopilotViewModel.cs @@ -20,11 +20,13 @@ using System.Linq; using System.Net; using System.Text.RegularExpressions; using System.Threading.Tasks; -using System.Windows.Forms; +using System.Windows; +using System.Windows.Input; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Stylet; using StyletIoC; +using DataFormats = System.Windows.Forms.DataFormats; using DragEventArgs = System.Windows.DragEventArgs; using Screen = Stylet.Screen; @@ -460,5 +462,22 @@ namespace MeoAsstGui { } } + + /// + /// 点击后移除界面中元素焦点 + /// + /// 点击事件发送者 + /// 点击事件 + public void MouseDown(object sender, MouseButtonEventArgs e) + { + if (!(sender is UIElement element)) + { + return; + } + + DependencyObject scope = FocusManager.GetFocusScope(element); + FocusManager.SetFocusedElement(scope, element); + Keyboard.ClearFocus(); + } } } diff --git a/src/MeoAsstGui/Views/CopilotView.xaml b/src/MeoAsstGui/Views/CopilotView.xaml index 4c24e35246..7842ea2d66 100644 --- a/src/MeoAsstGui/Views/CopilotView.xaml +++ b/src/MeoAsstGui/Views/CopilotView.xaml @@ -13,6 +13,7 @@ d:DesignWidth="800" AllowDrop="True" Drop="{s:Action DropFile}" + MouseDown="{s:Action MouseDown}" mc:Ignorable="d">