1

I have two styles

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

And this

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

If I try to use the second on an object like this

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

The compiler throw this error:

Error 16 the Style object cannot affect the Style property of the object to which it applies.

Why this happens ? How to implement it properly ?

Juan Pablo Gomez
  • 5,203
  • 11
  • 55
  • 101

2 Answers2

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

This should rectify an error. You tried to assign style to style.

Maximus
  • 3,458
  • 3
  • 16
  • 27
1

For BasedOn to work FontElemNivel1 will need to target a Textblock.

If doesn't suit because FontElemNivel1 needs to be used for something other than textblocks then maybe this previously answered question will help: XAML Combine Styles

Community
  • 1
  • 1
user3910810
  • 234
  • 1
  • 6