0

I'm fairly new to WPF and XAML, and I'm getting into the use of Resources.

In a ResourceDictionary, I have defined a SolidColorBrush thus:

<SolidColorBrush x:Key="ActiveTabBrush" Color="LightBlue" />

I use this in the XAML for my form like this:

Background="{DynamicResource ActiveTabBrush}"

I would also like to be able to access this SolidColorBrush in my C# code-behind, but I am at a loss to how to access such resources from code.

SolidColorBrush activeBrush = ?????;

Could somebody please tell me how I do this? I've spent a lot of time searching for the answer, but it's difficult to know what to search for.

Phil Rogers
  • 545
  • 4
  • 11
  • 1
    Try `var activeBrush = (SolidColorBrush) FindResource("ActiveTabBrush");` in code-behind. – thatguy Oct 28 '20 at 09:45
  • Thanks for the quick response. I had to use: (SolidColorBrush)Application.Current.FindResource("ActiveTabBrush"); but the principle is the same. I thought this must have been answered before, but I didn't know what to search for. – Phil Rogers Oct 28 '20 at 10:24

0 Answers0