fix: 修复ComboBox控件的PlaceholderForeground属性失效

This commit is contained in:
snail1519
2025-02-25 13:16:43 +08:00
parent 28ce72dda9
commit 78eda2d45a
3 changed files with 5 additions and 2 deletions

View File

@@ -12,7 +12,7 @@
<ComboBoxItem>BBB</ComboBoxItem> <ComboBoxItem>BBB</ComboBoxItem>
<ComboBoxItem>CCC</ComboBoxItem> <ComboBoxItem>CCC</ComboBoxItem>
</ComboBox> </ComboBox>
<ComboBox Width="100" PlaceholderText="Select"> <ComboBox Width="100" PlaceholderText="Select" PlaceholderForeground="Red">
<ComboBoxItem>AAA</ComboBoxItem> <ComboBoxItem>AAA</ComboBoxItem>
<ComboBoxItem>BBB</ComboBoxItem> <ComboBoxItem>BBB</ComboBoxItem>
<ComboBoxItem>CCC</ComboBoxItem> <ComboBoxItem>CCC</ComboBoxItem>
@@ -44,6 +44,7 @@
<Setter Property="HorizontalAlignment" Value="Left" /> <Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Top" /> <Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="MinHeight" Value="{DynamicResource ComboBoxDefaultHeight}" /> <Setter Property="MinHeight" Value="{DynamicResource ComboBoxDefaultHeight}" />
<Setter Property="PlaceholderForeground" Value="{DynamicResource ComboBoxSelectorPlaceHolderForeground}"/>
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="ComboBox"> <ControlTemplate TargetType="ComboBox">
<DataValidationErrors> <DataValidationErrors>
@@ -65,7 +66,7 @@
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
TextTrimming="CharacterEllipsis" TextTrimming="CharacterEllipsis"
Foreground="{TemplateBinding Foreground}" Foreground="{TemplateBinding PlaceholderForeground}"
IsVisible="{TemplateBinding SelectionBoxItem,Converter={x:Static ObjectConverters.IsNull}}" IsVisible="{TemplateBinding SelectionBoxItem,Converter={x:Static ObjectConverters.IsNull}}"
Opacity="0.3" Opacity="0.3"
Text="{TemplateBinding PlaceholderText}" /> Text="{TemplateBinding PlaceholderText}" />

View File

@@ -1,5 +1,6 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StaticResource x:Key="ComboBoxSelectorBackground" ResourceKey="SemiColorFill0" /> <StaticResource x:Key="ComboBoxSelectorBackground" ResourceKey="SemiColorFill0" />
<StaticResource x:Key="ComboBoxSelectorPlaceHolderForeground" ResourceKey="SemiColorText0" />
<StaticResource x:Key="ComboBoxSelectorPointeroverBackground" ResourceKey="SemiColorFill1" /> <StaticResource x:Key="ComboBoxSelectorPointeroverBackground" ResourceKey="SemiColorFill1" />
<StaticResource x:Key="ComboBoxSelectorFocusBackground" ResourceKey="SemiColorFill1" /> <StaticResource x:Key="ComboBoxSelectorFocusBackground" ResourceKey="SemiColorFill1" />
<StaticResource x:Key="ComboBoxSelectorPressedBackground" ResourceKey="SemiColorFill2" /> <StaticResource x:Key="ComboBoxSelectorPressedBackground" ResourceKey="SemiColorFill2" />

View File

@@ -1,5 +1,6 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StaticResource x:Key="ComboBoxSelectorBackground" ResourceKey="SemiColorFill0" /> <StaticResource x:Key="ComboBoxSelectorBackground" ResourceKey="SemiColorFill0" />
<StaticResource x:Key="ComboBoxSelectorPlaceHolderForeground" ResourceKey="SemiColorText0" />
<StaticResource x:Key="ComboBoxSelectorPointeroverBackground" ResourceKey="SemiColorFill1" /> <StaticResource x:Key="ComboBoxSelectorPointeroverBackground" ResourceKey="SemiColorFill1" />
<StaticResource x:Key="ComboBoxSelectorFocusBackground" ResourceKey="SemiColorFill1" /> <StaticResource x:Key="ComboBoxSelectorFocusBackground" ResourceKey="SemiColorFill1" />
<StaticResource x:Key="ComboBoxSelectorPressedBackground" ResourceKey="SemiColorFill2" /> <StaticResource x:Key="ComboBoxSelectorPressedBackground" ResourceKey="SemiColorFill2" />