Set static resource in code

前端 未结 3 461
粉色の甜心
粉色の甜心 2021-02-05 07:20

I have a few styles in my App.xaml file:




        
3条回答
  •  [愿得一人]
    2021-02-05 07:35

    Why are you modifying the Style instead of setting the Background-Property of your targeted StackPanel directly? Since a 'Local value' has a higher precedence than 'Style setters' the value that you write into Background from code behind would be used

    Means:

    (1) Give a name to your stackpanel x:Name="spBla"

    (2) Assign the Brush to the Background of spBla ( something like spBla.Background=Application.Current.Resources["styleRed"] as SolidColorBrush; )

    You can learn more about value precedence here:

    http://msdn.microsoft.com/en-us/library/ms743230(v=vs.110).aspx

提交回复
热议问题