1
votes

Solution: UserControl is not the actual type, so I cannot use Implicit Styles on usercontrols. Thanks Tim.

The following Implicit Style does not seem to do anything.

<Style TargetType="UserControl">
    <Setter Property="FontFamily" Value="Webdings"/>
    <Setter Property="Foreground" Value="Red"/>
</Style>

I know styles are getting loaded into the Apps resource dictionary because if I explicitly set another style in the same .xaml file it will work just fine.

Example:

<Style TargetType="Control" x:Key="BaseStyle">
    <Setter Property="FontFamily" Value="Webdings"/>
</Style>

Works fine if I put Style="{StaticResource BaseStyle}" in the tag. Thanks -Shane

1
Does it work if you specify your actual type instead of UserControl as the TargetType? - Tim
That's my problem. Implicit only works with specific type, and since all of my UserControls inherit from it, I cannot use implicit styles. Thanks. - shane
@Tim - you should promote your comment to an answer (even though it is short, maybe elaborate a little more) so that @shane can mark it as the answer. - slugster
@slugster - Good call. I've done that now. - Tim

1 Answers

2
votes

You need to specify the actual type of your control instead of just using UserControl. Implicit styles will only work with the specific type. So instead of:

<Style TargetType="UserControl">    
    <Setter Property="FontFamily" Value="Webdings"/>    
    <Setter Property="Foreground" Value="Red"/>
</Style>

you'd use:

<Style TargetType="my:MyUserControl">    
    <Setter Property="FontFamily" Value="Webdings"/>    
    <Setter Property="Foreground" Value="Red"/>
</Style>

where my is declared as your namespace and MyUserControl is the actual class name for your UserControl-derived controls.