views:

602

answers:

1

Hi !

I found out that I can use a different theme in an C# WPF Application by adding the theme .xaml-file to the project and add

to App.xaml as a Resource. see http://wpf.codeplex.com/wikipage?title=WPF%20Themes for a more detailed description.

Can I do this as well at runtime in C#? Is it possible to specify a different theme for different wpf windows?

Best regards Marc

+1  A: 

This blog post covers the basics, including the selection of theme at run time.

You can share themes between applications and have each one use a different one.

I didn't think you could mix themes within the same application, but marc40000 has found out you can:

<Button Height="23" Margin="81,65,122,0" Name="button1" VerticalAlignment="Top">
    <Button.Resources>
       <ResourceDictionary Source="ShinyBlue.xaml"/>
    </Button.Resources>
    Button
</Button>
<Button Height="23" HorizontalAlignment="Right" Margin="0,0,38,35" Name="button2" VerticalAlignment="Bottom" Width="75">Button</Button>

put the resourcedirectory to the controls you want to theme instead of doing it globaly in the app.xaml

There's even more information from this MSDN page and this one

ChrisF
For completeness: I found out that you can mix themes within the same app like this: <Button Height="23" Margin="81,65,122,0" Name="button1" VerticalAlignment="Top"> <Button.Resources> <ResourceDictionary Source="ShinyBlue.xaml"/> </Button.Resources> Button </Button> <Button Height="23" HorizontalAlignment="Right" Margin="0,0,38,35" Name="button2" VerticalAlignment="Bottom" Width="75">Button</Button> put the resourcedirectory to the controls you want to theme instead of doing it globaly in the app.xaml
marc40000
That's interesting - I'll update my answer
ChrisF