Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create skins for a GUI in WPF?

Tags:

c#

wpf

xaml

skins

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.

like image 1000
James Joshua Street Avatar asked Dec 15 '25 16:12

James Joshua Street


1 Answers

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);
like image 177
kmatyaszek Avatar answered Dec 17 '25 05:12

kmatyaszek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!