首页 > 解决方案 > Accessing a DynamicResource in code-behind

问题描述

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.

标签: c#wpfxamlresourcescode-behind

解决方案


推荐阅读