mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-18 10:10:45 +08:00
fix: ComboBox 的光标颜色不会随主题色变化
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
<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">
|
||||
<ResourceDictionary x:Class="MaaWpfGui.Res.Styles.ComboBox" 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" />
|
||||
<EventSetter Event="Loaded" Handler="ComboBox_Loaded_SetCaretBrush" />
|
||||
</Style>
|
||||
<Style BasedOn="{StaticResource ComboBoxExtend}" TargetType="{x:Type hc:ComboBox}">
|
||||
<Setter Property="Background" Value="{DynamicResource RegionBrushOpacity25}" />
|
||||
<Setter Property="uiBehaviors:ClipboardInterceptor.EnableSafeClipboard" Value="True" />
|
||||
<Setter Property="CaretBrush" Value="{DynamicResource PrimaryTextBrush}" />
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
|
||||
44
src/MaaWpfGui/Res/Styles/ComboBox.xaml.cs
Normal file
44
src/MaaWpfGui/Res/Styles/ComboBox.xaml.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace MaaWpfGui.Res.Styles
|
||||
{
|
||||
/// <summary>
|
||||
/// ComboBox 的光标颜色不会跟随主题变化
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
public partial class ComboBox
|
||||
{
|
||||
private void ComboBox_Loaded_SetCaretBrush(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not System.Windows.Controls.ComboBox cb)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SetCaret();
|
||||
|
||||
// 订阅 IsEditable 变化
|
||||
var dpd = DependencyPropertyDescriptor.FromProperty(System.Windows.Controls.ComboBox.IsEditableProperty, typeof(System.Windows.Controls.ComboBox));
|
||||
dpd.AddValueChanged(cb, (_, _) => SetCaret());
|
||||
return;
|
||||
|
||||
void SetCaret()
|
||||
{
|
||||
if (!cb.IsEditable)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cb.ApplyTemplate();
|
||||
if (cb.Template.FindName("PART_EditableTextBox", cb) is TextBox tb)
|
||||
{
|
||||
tb.CaretBrush = (Brush)Application.Current.Resources["PrimaryTextBrush"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user