Wpf 无法为标签设置属性前景
我正在尝试使用资源字典构建样式模板。我在为标签设置前景属性时遇到问题 很明显,我不明白这里的逻辑,有人能解释一下我的误解是什么,以及如何正确地应用它吗 当我移除Wpf 无法为标签设置属性前景,wpf,xaml,label,setter,Wpf,Xaml,Label,Setter,我正在尝试使用资源字典构建样式模板。我在为标签设置前景属性时遇到问题 很明显,我不明白这里的逻辑,有人能解释一下我的误解是什么,以及如何正确地应用它吗 当我移除 <Setter Property="Foreground" Value="AliceBlue"/> 这是当前的代码 <Style TargetType="Label"> <Setter Property="Height" Value="30" /> <Sette
<Setter Property="Foreground" Value="AliceBlue"/>
这是当前的代码
<Style TargetType="Label">
<Setter Property="Height" Value="30" />
<Setter Property="Width" Value="120" />
<Setter Property="Margin" Value="1" />
<Setter Property="Padding" Value="1" />
<Setter Property="Foreground" Value="AliceBlue"/>
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="FontFamily" Value="{DynamicResource STAC_FontFamily_Standard}" />
<Setter Property="FontSize" Value="{DynamicResource STAC_FontSize_Medium}" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Label">
<Border>
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
RecognizesAccessKey="True"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
到目前为止,我已经尝试了我记录的以下组合,以及更多
<Setter Property="TextElement.Foreground" Value="AliceBlue" />
<Setter Property="Foreground" Value="{DynamicResource STAC_Col_Label_Fg}"/>
<Setter Property="Foreground" Value="AliceBlue"/>
<Setter Property="TextBlock.Foreground" Value="AliceBlue"/>
Also tried
<Setter Property="Foreground" Value="AliceBlue"/>
with
TextBlock.Foreground="{TemplateBinding Foreground}"
inside the content presenter
也试过
具有
TextBlock.Foreground=“{TemplateBinding Foreground}”
在内容演示器内部
当然在标签样式中起作用。根据你在这里展示的内容,我们无法解释为什么它不适合你。将其归类为封闭的、陡峭的学习曲线这些模板,如果你在需要颜色时添加brush类型的资源,或者反之亦然,似乎会导致难以跟踪的问题
<Setter Property="TextElement.Foreground" Value="AliceBlue" />
<Setter Property="Foreground" Value="{DynamicResource STAC_Col_Label_Fg}"/>
<Setter Property="Foreground" Value="AliceBlue"/>
<Setter Property="TextBlock.Foreground" Value="AliceBlue"/>
Also tried
<Setter Property="Foreground" Value="AliceBlue"/>
with
TextBlock.Foreground="{TemplateBinding Foreground}"
inside the content presenter