mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-18 02:10:21 +08:00
fix: ComboBox 剪贴板异常
This commit is contained in:
@@ -26,7 +26,7 @@ namespace MaaWpfGui.Extensions.UIBehaviors
|
||||
"EnableSafeClipboard",
|
||||
typeof(bool),
|
||||
typeof(ClipboardInterceptor),
|
||||
new PropertyMetadata(false, OnEnableSafeClipboardChanged));
|
||||
new(false, OnEnableSafeClipboardChanged));
|
||||
|
||||
public static void SetEnableSafeClipboard(DependencyObject element, bool value)
|
||||
=> element.SetValue(EnableSafeClipboardProperty, value);
|
||||
@@ -47,26 +47,42 @@ namespace MaaWpfGui.Extensions.UIBehaviors
|
||||
case DataGrid dg when (bool)e.NewValue:
|
||||
AddCommandBindingsToDataGrid(dg);
|
||||
break;
|
||||
case ComboBox cb when (bool)e.NewValue && cb.IsEditable:
|
||||
cb.Loaded += OnComboBoxLoaded;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddCommandBindingsToTextBox(TextBox tb)
|
||||
{
|
||||
tb.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, OnCopyTextBox));
|
||||
tb.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, OnCutTextBox));
|
||||
tb.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, OnPasteTextBox));
|
||||
tb.CommandBindings.Add(new(ApplicationCommands.Copy, OnCopyTextBox));
|
||||
tb.CommandBindings.Add(new(ApplicationCommands.Cut, OnCutTextBox));
|
||||
tb.CommandBindings.Add(new(ApplicationCommands.Paste, OnPasteTextBox));
|
||||
}
|
||||
|
||||
private static void AddCommandBindingsToRichTextBox(RichTextBox rtb)
|
||||
{
|
||||
rtb.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, OnCopyRichTextBox));
|
||||
rtb.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, OnCutRichTextBox));
|
||||
rtb.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, OnPasteRichTextBox));
|
||||
rtb.CommandBindings.Add(new(ApplicationCommands.Copy, OnCopyRichTextBox));
|
||||
rtb.CommandBindings.Add(new(ApplicationCommands.Cut, OnCutRichTextBox));
|
||||
rtb.CommandBindings.Add(new(ApplicationCommands.Paste, OnPasteRichTextBox));
|
||||
}
|
||||
|
||||
private static void AddCommandBindingsToDataGrid(DataGrid dg)
|
||||
{
|
||||
dg.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, OnCopyDataGrid));
|
||||
dg.CommandBindings.Add(new(ApplicationCommands.Copy, OnCopyDataGrid));
|
||||
}
|
||||
|
||||
private static void OnComboBoxLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not ComboBox cb)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (cb.Template.FindName("PART_EditableTextBox", cb) is TextBox textBox)
|
||||
{
|
||||
AddCommandBindingsToTextBox(textBox);
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnCopyTextBox(object sender, ExecutedRoutedEventArgs e)
|
||||
@@ -213,7 +229,7 @@ namespace MaaWpfGui.Extensions.UIBehaviors
|
||||
if (sender is not DataGrid dg)
|
||||
{
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
// 获取选中单元格内容,拼成制表符分隔的文本
|
||||
var selectedCells = dg.SelectedCells;
|
||||
@@ -253,6 +269,5 @@ namespace MaaWpfGui.Extensions.UIBehaviors
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:hc="https://handyorg.github.io/handycontrol">
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:uiBehaviors="clr-namespace:MaaWpfGui.Extensions.UIBehaviors">
|
||||
|
||||
<Style BasedOn="{StaticResource ComboBoxExtend}" TargetType="{x:Type ComboBox}">
|
||||
<Setter Property="Background" Value="{DynamicResource RegionBrushOpacity25}" />
|
||||
<Setter Property="uiBehaviors:ClipboardInterceptor.EnableSafeClipboard" Value="True" />
|
||||
</Style>
|
||||
<Style BasedOn="{StaticResource ComboBoxExtend}" TargetType="{x:Type hc:ComboBox}">
|
||||
<Setter Property="Background" Value="{DynamicResource RegionBrushOpacity25}" />
|
||||
<Setter Property="uiBehaviors:ClipboardInterceptor.EnableSafeClipboard" Value="True" />
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
|
||||
Reference in New Issue
Block a user