Can UserControls have implicit styles in Silverlight?
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
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.
精彩评论