Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在WinRT XAML中禁用组合框时更改占位符文本颜色_C#_Xaml_Combobox_Windows Runtime_Winrt Xaml - Fatal编程技术网

C# 在WinRT XAML中禁用组合框时更改占位符文本颜色

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

在我的Windows8.1项目中,我有一个带有自定义样式的组合框,这样我就可以更改占位符文本的前景色

当组合框被禁用时,此自定义前景颜色太浅,因此我希望能够更改此占位符文本颜色

更改ComboBoxDisabledForegroundThemeBrush只会影响实际的组合框文本,而不会影响占位符文本,而且我看不到任何方法可以控制占位符文本块前景的不同视觉状态

占位符文本颜色能否由视觉状态控制

<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>


我希望保留原始帖子中指定的自定义前景色,但希望能够控制禁用的前景色。我希望保留原始帖子中指定的自定义前景色,但希望能够控制禁用的前景色。