我有两种风格
<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/