Tag: app.xaml

在代码中设置静态资源

我的App.xaml文件中有几个样式: 我想在mainpage.xaml.cs的代码中更改BackgroundProperty 。 我试过用这个: Style style = Application.Current.Resources[“stackpanelBackground”] as Style; style.Setters.SetValue(StackPanel.BackgroundProperty, “{StaticResource styleRed}”); 但我遇到了灾难性的失败exception。 我认为它与{StaticResource styleRed} 。 有一个更好的方法吗?