Reputation: 1123
I am defining resources in my App.XAML file:
<SolidColorBrush x:Key="ActivePanelBackgBrush" Color="#FF77FF83"/>
<SolidColorBrush x:Key="NonActivePanelBackgBrush" Color="#FFFF7777"/>
In my C# code I would like to set the background of a Grid to that color. How do I do that?
Thx
Upvotes: 1
Views: 3007
Reputation: 26635
You can get objects from Resources in App.xaml like that:
var brush = Application.Current.Resources["NonActivePanelBackgBrush"] as SolidColorBrush;
And use it where you want:
Grid1.Background = brush;
Alternatively you can use FindResource
.
However, WinRT seemed to be missing the FindResource
function which is familiar from WPF. You can use this extension method.( sadly I have not tested it yet)
Grid1.Background = FindResource("NonActivePanelBackgBrush") as SolidColorBrush;
Upvotes: 5