C# 在WinRT XAML中禁用组合框时更改占位符文本颜色
在我的Windows8.1项目中,我有一个带有自定义样式的组合框,这样我就可以更改占位符文本的前景色 当组合框被禁用时,此自定义前景颜色太浅,因此我希望能够更改此占位符文本颜色 更改ComboBoxDisabledForegroundThemeBrush只会影响实际的组合框文本,而不会影响占位符文本,而且我看不到任何方法可以控制占位符文本块前景的不同视觉状态 占位符文本颜色能否由视觉状态控制C# 在WinRT XAML中禁用组合框时更改占位符文本颜色,c#,xaml,combobox,windows-runtime,winrt-xaml,C#,Xaml,Combobox,Windows Runtime,Winrt Xaml,在我的Windows8.1项目中,我有一个带有自定义样式的组合框,这样我就可以更改占位符文本的前景色 当组合框被禁用时,此自定义前景颜色太浅,因此我希望能够更改此占位符文本颜色 更改ComboBoxDisabledForegroundThemeBrush只会影响实际的组合框文本,而不会影响占位符文本,而且我看不到任何方法可以控制占位符文本块前景的不同视觉状态 占位符文本颜色能否由视觉状态控制 <Style x:Key="MyCustomStyle" TargetType="ComboBox
<Style x:Key="MyCustomStyle" TargetType="ComboBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledBackgroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledBorderThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="DropDownGlyph">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxArrowDisabledForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
...
<ContentPresenter x:Name="ContentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" Grid.Row="1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<TextBlock x:Name="PlaceholderTextBlock" Foreground="#FFAAAAAA" FontWeight="Normal" Text="{TemplateBinding PlaceholderText}"/>
</ContentPresenter>
...
您要查找的画笔在组合框
的样式下被命名为组合框占位符文本forgroundthemebrush
.....
<ContentPresenter x:Name="ContentPresenter"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
Grid.Row="1"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<TextBlock x:Name="PlaceholderTextBlock"
Foreground="{ThemeResource ComboBoxPlaceholderTextForegroundThemeBrush}"
FontWeight="{ThemeResource ComboBoxPlaceholderTextThemeFontWeight}"
Text="{TemplateBinding PlaceholderText}" />
</ContentPresenter>
....
。。。。。
....
您可以像这样单独处理占位符前景
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground"
Storyboard.TargetName="PlaceholderTextBlock">
<DiscreteObjectKeyFrame KeyTime="0"
Value="Black" />
</ObjectAnimationUsingKeyFrames>
您要查找的画笔在
组合框
的样式下被命名为组合框占位符文本forgroundthemebrush
.....
<ContentPresenter x:Name="ContentPresenter"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
Grid.Row="1"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<TextBlock x:Name="PlaceholderTextBlock"
Foreground="{ThemeResource ComboBoxPlaceholderTextForegroundThemeBrush}"
FontWeight="{ThemeResource ComboBoxPlaceholderTextThemeFontWeight}"
Text="{TemplateBinding PlaceholderText}" />
</ContentPresenter>
....
。。。。。
....
您可以像这样单独处理占位符前景
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground"
Storyboard.TargetName="PlaceholderTextBlock">
<DiscreteObjectKeyFrame KeyTime="0"
Value="Black" />
</ObjectAnimationUsingKeyFrames>
我希望保留原始帖子中指定的自定义前景色,但希望能够控制禁用的前景色。我希望保留原始帖子中指定的自定义前景色,但希望能够控制禁用的前景色。