locked
Themes RRS feed

  • Question

  • I am looking to set up a group of themes, or rather templates. The aim is to provide a template where each time I create an application all of the buttons etc will look the same.

    In Windows forms it would be done by creating user controls, right? I guess this is an option for WPF, however, if I created a set of themes and saved them in a namespace and then created a project template that set this theme as a style, it should work??

    Please correct any errors in my logic and please point me to any specific resources for achieving my goal.

    I've read teh WPF chapter in Pro C# 2008 and have had lots of fun playing. Now I want to go to my boss with definite answers about how we could have a consistent, company-wide style to our applications.

    Thanks in advance.
    Tuesday, June 23, 2009 7:48 AM

Answers

  • Hi,

    If what you want is to create multiple theme files for your application,then create different ResourceDictionary files,theme1.xaml ,theme2.xaml etc, where you have to give the different styles

    Using some theme selector button in your application you can dynamically switch the theme file being used.See this link for that

    Hope it helps

    FEAR NOT TO BE JUST Please mark posts as answers/helpful if it answers your query
    Tuesday, June 23, 2009 9:53 AM
  • In WPF you have more than one option:

    1) Like Rahul suggested. Just put your styles/templates in a resource dictionary (or split them up using merged dictionaries) and load the dictionary at application level (app.xaml), or from code, in every application you create. This is what is usually called 'skinning'.

    2) A more advanced form of step 1 is to create a custom control library. Note that I'm not talking about a usercontrol here, but actually create your own subclass by inheriting from one of the standard WPF controls, instead of inheriting from UserControl. Your controls usually will have their own default style/template defined in a file called generic.xaml (or by using merged dictionaties). However, the main reason for doing this should be that you want to add functionality (code), not just for changing presentation (xaml)!
    Your library (a .dll file) can then be referenced in another application and the developer should use your controls instead of the standard WPF ones to get your skin.

    3) Advancing on step 2 is theming. In this scenario you can even provide variations of the styles/templates in step 2 to make the styling fit in better with the Windows theme that the end user's system is using. In that way your application can have a different appearance on, for example, Windows XP than on Windows Vista.

    I have an example of step 2 over here (although I didn't add any functionality to the custom control):
    (edit: actually it's a combination of step 1 and 2)

    hth,
    Marcel
    • Edited by DutchMarcel Tuesday, June 23, 2009 11:58 AM added info
    • Proposed as answer by Rahul P Nath Tuesday, June 23, 2009 12:03 PM
    • Marked as answer by Jim Zhou - MSFT Monday, June 29, 2009 11:33 AM
    Tuesday, June 23, 2009 11:53 AM

All replies

  • Hi,

    If what you want is to create multiple theme files for your application,then create different ResourceDictionary files,theme1.xaml ,theme2.xaml etc, where you have to give the different styles

    Using some theme selector button in your application you can dynamically switch the theme file being used.See this link for that

    Hope it helps

    FEAR NOT TO BE JUST Please mark posts as answers/helpful if it answers your query
    Tuesday, June 23, 2009 9:53 AM
  • In WPF you have more than one option:

    1) Like Rahul suggested. Just put your styles/templates in a resource dictionary (or split them up using merged dictionaries) and load the dictionary at application level (app.xaml), or from code, in every application you create. This is what is usually called 'skinning'.

    2) A more advanced form of step 1 is to create a custom control library. Note that I'm not talking about a usercontrol here, but actually create your own subclass by inheriting from one of the standard WPF controls, instead of inheriting from UserControl. Your controls usually will have their own default style/template defined in a file called generic.xaml (or by using merged dictionaties). However, the main reason for doing this should be that you want to add functionality (code), not just for changing presentation (xaml)!
    Your library (a .dll file) can then be referenced in another application and the developer should use your controls instead of the standard WPF ones to get your skin.

    3) Advancing on step 2 is theming. In this scenario you can even provide variations of the styles/templates in step 2 to make the styling fit in better with the Windows theme that the end user's system is using. In that way your application can have a different appearance on, for example, Windows XP than on Windows Vista.

    I have an example of step 2 over here (although I didn't add any functionality to the custom control):
    (edit: actually it's a combination of step 1 and 2)

    hth,
    Marcel
    • Edited by DutchMarcel Tuesday, June 23, 2009 11:58 AM added info
    • Proposed as answer by Rahul P Nath Tuesday, June 23, 2009 12:03 PM
    • Marked as answer by Jim Zhou - MSFT Monday, June 29, 2009 11:33 AM
    Tuesday, June 23, 2009 11:53 AM