c# - Style 对象不能影响它所应用的对象的 Style 属性

标签 c# wpf xaml

我有两种风格

<Style x:Key="FontElemNivel1">
    <Setter Property="TextElement.FontSize" Value="12"/>
    <Setter Property="TextElement.FontFamily" Value="Tahoma"/>
    <Setter Property="TextElement.FontWeight" Value="Bold"/>
</Style>

还有这个

<Style x:Key="ElementoNivel1" TargetType="TextBlock">
    <Setter Property="Style" Value="{StaticResource FontElemNivel1}"/>
    <Setter Property="HorizontalAlignment" Value="Left"/>
</Style>

如果我尝试在这样的对象上使用第二个

<TextBlock Text="Entidad"  Style="{DynamicResource ElementoNivel1}"/>

编译器抛出这个错误:

错误 16 Style 对象不能影响它所应用的对象的 Style 属性。

为什么会这样? 如何正确实现?

最佳答案

<Style x:Key="ElementoNivel1" TargetType="TextBlock" BasedOn="{StaticResource FontElemNivel1}">

这应该可以纠正错误。您试图将样式分配给样式。

关于c# - Style 对象不能影响它所应用的对象的 Style 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25170100/

相关文章:

c# - 64 位 Windows 上的 P/Invoke 是否需要与 32 位 Windows 不同的签名?

c# - MVVM DDD 应用程序中的组合根

c# - 如何从 xaml 中该行中的模板化单元格绑定(bind)到 DataGridRow 项目?

wpf - 将 Tab 键顺序限制为单个用户控件 (WPF)

WPF GroupBox header 自定义

wpf - 动画 TranslateTransform.Y 到控件的高度(目的是将元素滑出视线)

xaml - Xamarin 表单从 ListView 绑定(bind)到 View 模型

c# - 求连续素数之和

c# - Linq-to-XML XElement.Remove() 留下不需要的空白

wpf - 如何在 WPF 中禁用 ListView Header 的移动/重新排序?