locked
How to define global styles for Button, Combobox, Checkbox RRS feed

  • Question

  • Hello


    I am starting in Silverlight development and I search how to define global styles for button, combobox, checkbox in all my view.
    I have realized these operations but I found that it is very long and I don't know if it is the good method.
    In the file "Styles.xaml" I have defined <Style> for "Button", "CheckBox", "Combobox" like this:
    <Style x:key="ButtonStyle1" TargetType="Button">  ...   </Style>
    <Style x:key="CheckBoxStyle1" TargetType="CheckBox">  ...  </Style>
    <Style x:key="ComboBoxStyle1" TargetType="ComboBox">  ...  </Style>
    and in each view for each button, combobox, checkbox, I have add:
    Style ="{staticResource ButtonStyle1}"
    Style ="{staticResource CheckBoxStyle1}"
    Style ="{staticResource ComboBoxStyle1}"
    All works very well but it is very long to edit XAML code for each components


    My question: Is it possible to add "Style" in "Style.xaml" file and apply Style directly without adding the word "Style ="{staticResource xxxxxStyle1}" "after each component?


    Thank you for your help. 

    Best regards.

    Christian

     

    Wednesday, September 29, 2010 9:11 AM

Answers

  • In App.xaml, you create another style based on style "ButtonStyle"

     <Style x:Key="b1" TargetType="Button">
                <Setter Property="FontSize" Value="15"/>
     </Style>

     <Style TargetType="Button" BasedOn="{StaticResource b1}"/>
    Wednesday, September 29, 2010 10:01 AM

All replies

  • In App.xaml, you create another style based on style "ButtonStyle"

     <Style x:Key="b1" TargetType="Button">
                <Setter Property="FontSize" Value="15"/>
     </Style>

     <Style TargetType="Button" BasedOn="{StaticResource b1}"/>
    Wednesday, September 29, 2010 10:01 AM
  • It is OK .  Thank you very much

    Christian

    Wednesday, September 29, 2010 11:23 AM