3

I was wondering how I should go about creating custom settings for all the color schemes and such. I know I can create styles for individual components or parts..but how should I create a set of skins?

for example, right now I'm using a maroon colored gradientbrush in a lot of subcontrols. However, I'm sure that people other than me will hate the color scheme.

I know that I can create a dependency property on my top level control for the color and then bind the individual parts that need that color to that dependency property. However, there will need to be many properties. Should I just create a separate style object that contains all these properties and place it as field in my user control?

I'm just wondering if there are other ways of doing this in WPF. For example, I guess there could be some way of doing this in xaml or utilizing some built in class in the default libraries.

James Joshua Street
  • 3,259
  • 10
  • 42
  • 80

1 Answers1

2

You can do this by creating new resource dictionary and define there colors and control templates for your controls.

Example you can find in WPF Themes project (download link).

You can change your style by changing resource dictionary, e.g:

<Application x:Class="ThemesSample.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="Window1.xaml">
    <Application.Resources>
        <ResourceDictionary Source="ExpressionDark.xaml"/>
    </Application.Resources>
</Application>

If you want to change theme at runtime you should use following code:

ResourceDictionary dict = new ResourceDictionary();
dict.Source = new Uri("BureauBlack.xaml", UriKind.Relative);
this.Resources.MergedDictionaries.Add(dict);
kmatyaszek
  • 19,016
  • 9
  • 60
  • 65
  • I guess I'm wondering whether there is any way to switch resource directories in xaml or whether i have to do it in code behind if I want to be able to shift styles at runtime. I am also curious whether this is the sort of place where MVVM comes in, and you define a new view that has different styles defined or something. – James Joshua Street Aug 03 '13 at 23:57
  • 1
    @JamesJoshuaStreet if you want to change style at runtime you should do this in code behind. If your view has different style you can add to view resources appropriate style by using MergedDictionaries. – kmatyaszek Aug 04 '13 at 10:23