Set static resource in code
I have a few styles in my App.xaml file: <SolidColorBrush x:Key="styleBlue" Color="#FF4B77BE"/> <SolidColorBrush x:Key="styleRed" Color="#FFF64747"/> <SolidColorBrush x:Key="styleOrange" Color="#FFF89406"/> <SolidColorBrush x:Key="styleGreen" Color="#FF1BBC9B"/> <SolidColorBrush x:Key="styleYellow" Color="#FFF9BF3B"/> <Style x:Key="stackpanelBackground" TargetType="StackPanel"> <Setter Property="Background" Value="{StaticResource styleBlue}"/> </Style> I want to change the BackgroundProperty in the code of my mainpage.xaml.cs . I tried using this: Style style = Application.Current.Resources[