views:

57

answers:

1

I want let the user choose what style my application has.Small example would be 2 buttons, if user presses button 1 then the background color turns red, if the user presses button 2 then the backgroundcolor turns green.

How do i do that? do i use multiple resource dictionaries? and apply them when the button is pressed? Whats the most common way of doing that?

A: 

As a very simple example:

 <Window.Resources>
    <Style TargetType="Window" x:Key="windowStyleOne">
        <Setter Value="123" Property="Content" />
        <Setter Value="Red" Property="Background"/>
    </Style>
    <Style TargetType="Window" x:Key="windowStyleTwo">
        <Setter Value="456" Property="Content" />
        <Setter Value="Green" Property="Background" />
    </Style>
</Window.Resources>

<Button Name ="myButtonOne"  Click="ButtonOne_Click">Red</Button>
<Button Name="myButtonTwo" Click="ButtonTwo_Click">Green</Button>


private void ButtonOne_Click(object sender, RoutedEventArgs e)
{   
   this.Style = (Style)(this.Resources["windowStyleOne"]);
}

private void ButtonTwo_Click(object sender, RoutedEventArgs e)
{
    this.Style = (Style)(this.Resources["windowStyleTwo"]);
}

EDIT: Actually heres an example that fits with your suggested example perfectly. myButtonOne makes the main window have a red background and myButtonTwo sets the window to have a green background.

MoominTroll
thanks , just what i needed
MichaelD