开发者

WPF: Accessing a style of ResourceDictionary from inside of usercontrol

开发者 https://www.devze.com 2023-01-10 21:08 出处:网络
Normally, to set style using C#, I write, btn.Style = (Style)FindResource(_styleName); But what to do, if style is defined inside main \'ResourceDictionary\', and button is inside some \'UserControl

Normally, to set style using C#, I write,

btn.Style = (Style)FindResource(_styleName);

But what to do, if style is defined inside main 'ResourceDictionary', and button is inside some 'UserControl'. Also, I need to write script inside 'UserControl' only.

To make i开发者_JS百科t more clear - There is a button inside UserControl which should take style defined in main ResourceDictionary. It should happen on some event of usercontrol, so I need to write CS in usercontrol.xaml.cs. It is quite easy if style is defined in usercontrol.xaml itself.


if it is inside the Application resources

SolidColorBrush res = (SolidColorBrush) Application.Current.FindResource("YellowSolidBrush");

0

精彩评论

暂无评论...
验证码 换一张
取 消