我正在尝试使用资源字典构建样式模板。我在将前景属性设置为标签时遇到问题。
我显然错过了这里的逻辑,有人可以向我解释一下我的误解以及如何正确应用这个
当我删除
时<Setter Property="Foreground" Value="AliceBlue"/>
并运行项目,一切都很好
然而,在该行中,我收到以下错误
System.Windows.Markup.XamlParseException was unhandled
Message: An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: 'Initialization of 'System.Windows.Controls.Label' threw an exception.' Line number '31' and line position '135'.
这是当前的代码
<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