Giangregorio has covered most of the reason this cannot be achieved directly. However, here is the solution:
You can use DynamicResource links in your Setters style, and then when you need to change the style, you just update the resource , not the style. This probably makes more sense with an example:
<SolidColorBrush x:Key="BlueBrush" Color="Blue"/> <SolidColorBrush x:Key="RedBrush" Color="Red"/> <Style x:Key="MainMenuStyle" TargetType="{x:Type TextBlock}"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property= "Foreground" Value="{DynamicResource BlueBrush}"/> ... </Trigger> <Trigger Property="IsMouseOver" Value="False"> <Setter Property= "Foreground" Value="{DynamicResource RedBrush}" /> ... </Trigger> </Style.Triggers> </Style>
So. Because Foreground properties reference DynamicResource , whenever a resource changes, it updates the Style value. All you have to do in the code is change the value of the resource.
App.Current.Resources["BlueBrush"] = new SolidColorBrush(Colors.Pink);
DynamicResource takes care of the rest.
source share