Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.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# 当TextBlock类型具有全局样式时,如何更改cutom标签的前景色_C#_Wpf_Xaml_Label - Fatal编程技术网

C# 当TextBlock类型具有全局样式时,如何更改cutom标签的前景色

C# 当TextBlock类型具有全局样式时,如何更改cutom标签的前景色,c#,wpf,xaml,label,C#,Wpf,Xaml,Label,现在,我将TextBlock类型的样式定义为全局资源,换句话说,TextBlock现在在我的应用程序中具有默认样式。我想为标签添加一个底部边框。但我不知道如何更改标签前景色中的文本块,如我想要的 想让它的前景色变成蓝色。现在,标签的子子子项TextBlock使用默认样式 <Style x:TargetType="{x:Type TextBlock}"> <Setter Property="Foreground" Value="#FFFFF0" /> </St

现在,我将TextBlock类型的样式定义为全局资源,换句话说,TextBlock现在在我的应用程序中具有默认样式。我想为标签添加一个底部边框。但我不知道如何更改标签前景色中的文本块,如我想要的 想让它的前景色变成蓝色。现在,标签的子子子项TextBlock使用默认样式

<Style x:TargetType="{x:Type TextBlock}">
   <Setter Property="Foreground" Value="#FFFFF0" /> 
</Style>

<Style x:Key="{x:Type Label}"
   TargetType="Label">
<Setter Property="HorizontalContentAlignment"
      Value="Left" />
<Setter Property="VerticalContentAlignment"
      Value="Top" />
<Setter Property="Template">
<Setter.Value>
  <ControlTemplate TargetType="Label">
    <Border>
      <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                        RecognizesAccessKey="True" />
    </Border>
    <ControlTemplate.Triggers>
      <Trigger Property="IsEnabled"
               Value="false">
        <Setter Property="Foreground">
          <Setter.Value>
            <SolidColorBrush Color="{DynamicResource DisabledForegroundColor}" />
          </Setter.Value>
        </Setter>
      </Trigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>
</Setter.Value>
 </Setter>
</Style>
解决方案一: 该样式可以为标签添加底部边框,并替代全局文本块样式


你想动态地改变标签的预览吗?首先,我想让它成为一个SATE资源。也许我会认为它是动态变化的。
 <Style TargetType="Label" x:Key="TodoPlaceHolder">
    <Setter Property="FontWeight" Value="Bold" />
    <Setter Property="FontFamily" Value="Corbel" />
    <Setter Property="FontSize" Value="18" />
    <Setter Property="Foreground" Value="#F0F0F0" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Label">

                <Border SnapsToDevicePixels="true" x:Name="Bd" Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">

                    <TextBlock HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                               Text="{TemplateBinding Content}"
                               Foreground="{TemplateBinding Foreground}"
                               FontFamily="{TemplateBinding FontFamily}"
                               FontSize="{TemplateBinding FontSize}"
                               FontWeight="{TemplateBinding FontWeight}"
                             Margin="{TemplateBinding Margin}">
                    </TextBlock>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
<ContentPresenter TextBlock.FontFamily="Tahoma"
              TextBlock.FontWeight="Bold"
              SnapsToDevicePixels="True"
              HorizontalAlignment="Left"
              Margin="4,0,0,0"
              ContentSource="Header"
              VerticalAlignment="Center"
              RecognizesAccessKey="True" />