How to change the dynamic resource in the Button Click

Mar 10 2016 2:24 AM
I am new to WPF and i need to learn the static resource and dynamic resource. i have tried to set the style for button using the Dynamic Resource and change the style using button Click but the style is not changed. please refer my code i used for change the button style using click
 
Codes :
 
<Window.Resources>
<Style x:Key="Style1" TargetType="Button">
<Setter Property="Background" Value="Red" />
</Style>
</Window.Resources>
<Button x:Name="Content" Content="Content" Height="30" Width="200" Style="{DynamicResource ResourceKey=Style1}" Click="Content_Click" />
 
Click :
private void Content_Click(object sender, RoutedEventArgs e)
{
this.Resources.Add("Style1", new SolidColorBrush(Colors.Blue));
}
Could you please any one guide me how to achieve my requirement.
 

Answers (2)