none
Is it possible to combine multiple styles?

    Question

  • I'm looking for way to apply more than one style to an element much like you were able to do with css in hopes that I can reduce my need for creating a permutation of styles...

    As an example, let's say I had several Button styles like this:

    <Style x:Key="basestyle" TargetType="Button">
      <!-- some button style -->
    </Style>

    <Style x:Key="s1" TargetType="Button">
      <Setter Property="BorderThickness" Value="0"/>
    </Style>

    <Style x:Key="s2" TargetType="Button">
      <Setter Property="BorderBrush" Value="Red"/>
    </Style>

    <Style x:Key="s3" TargetType="Button">
      <Setter Property="Foreground" Value="Blue"/>
    </Style>


    And I wanted to use the styles like this:

    <Button Style="{basestyle+s1+s3}" />

    <Button Style="{basestyle+s2}" />

    <Button Style="{basestyle+s1+s2+s3}" />



    Is this possible?  Has anybody done anything similar?


     

    Wednesday, September 01, 2010 1:39 PM

Answers

All replies

  • Hi

    It is possible with the help of BasedOn property please follow this link:

    http://www.silverlightshow.net/tips/Tip-Cascading-Styles-in-Silverlight-3.aspx

    And

    http://10rem.net/blog/2009/03/18/silverlight-3-%E2%80%93-basedon-styles

    Wednesday, September 01, 2010 11:47 PM
  • u can use BasedOn property of Style.

    it is similar to inheritance. 

    Thursday, September 02, 2010 5:26 AM
  • No, this is a little more complex than BasedOn.  I don't want to create N permutations of the styles, I just want to be able to apply them (multiples of them) where needed... 

    Thursday, September 02, 2010 8:16 AM
  • AFAIK, u should create different style combining the styles!

    Thursday, September 02, 2010 9:08 AM