Wednesday, July 21, 2010

Concatenation of Styles in WPF

In order to avoid confusion and/or be inline with OOP concepts, WPF style will not allow you to concatenate multiple style in one control. Instead, you can use ‘BasedOn’ property (of Style element) to inherit from the other style. It is possible to create chain of inheritance but multiple inheritance is not supported by default. Initially I though it is not possible  until I came across this amazing link: http://swdeveloper.wordpress.com/2009/01/03/wpf-xaml-multiple-style-inheritance-and-markup-extensions/

It shows use of MarkupExtension to enable inheritance from multiple styles (in actual, your triggers and setters will be merged. Duplicates will be overwritten by the second style that you define)

Happy interfacing!