Is it possible to combine multiple styles?


  • 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 x:Key="s1" TargetType="Button">
      <Setter Property="BorderThickness" Value="0"/>

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

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

    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


All replies

  • Hi

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


    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