Silverlight 4 and Implicit styling

不想你离开。 提交于 2019-12-07 17:00:32

问题


In Silverlight 4 it's possible to use implicit styling - and that is amazing! But what if I want to apply a style to all of my Buttons, CheckBoxes and RadioButtons (all inheriting from ButtonBase)? I can't set TargetType on the Style to ButtonBase - that doesn't work. Do I need to create a style to each of the 3 control types?


回答1:


http://www.silverlightshow.net/items/Implicit-Styles-in-Silverlight-4.aspx Try this




回答2:


xamlgeek,

The following implicit styles work well for me. I first create some name/keyed styles, using common BasedOn styles whereever possible. Then I simply create the implicit styles BasedOn those named/keyed styles...

<Style x:Key="BaseStyle" TargetType="Control">
    <Setter Property="FontFamily" Value="{StaticResource FontFamily}" />
    <Setter Property="FontSize" Value="{StaticResource FontSize}" />
    <Setter Property="Foreground" Value="{StaticResource FontBrush}" />
</Style>
<Style x:Key="BaseStyleCentered" TargetType="Control" BasedOn="{StaticResource BaseStyle}">
    <Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style x:Key="CommonCheckBox" TargetType="CheckBox" BasedOn="{StaticResource BaseStyleCentered}">
    <Setter Property="Cursor" Value="Hand" />
</Style>
<Style x:Key="CommonRadioButton" TargetType="RadioButton" BasedOn="{StaticResource BaseStyleCentered}">
    <Setter Property="Cursor" Value="Hand" />
</Style>
<Style x:Key="CommonButton" TargetType="Button" BasedOn="{StaticResource BaseStyleCentered}">
    <Setter Property="Cursor" Value="Hand" />
    <Setter Property="Padding" Value="10,0,10,0" />
    <Setter Property="MinWidth" Value="{StaticResource ButtonWidth}" />
    <Setter Property="MinHeight" Value="{StaticResource ButtonHeight}" />
</Style>
<Style TargetType="CheckBox" BasedOn="{StaticResource CommonCheckBox}">
</Style>
<Style TargetType="RadioButton" BasedOn="{StaticResource CommonRadioButton}">
</Style>
<Style TargetType="Button" BasedOn="{StaticResource CommonButton}">
</Style>

Good luck,

Jim

YinYangMe, YinYangMoney and FaceToFaceSoftware



来源:https://stackoverflow.com/questions/2363774/silverlight-4-and-implicit-styling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!