WPF:从usercontrol内部访问ResourceDictionary样式

时间:2010-08-11 05:31:14

标签: wpf user-controls styles

通常,要使用C#设置样式,我写,

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

但该怎么做,如果在主'ResourceDictionary'中定义了style,而button在某个'UserControl'中。另外,我只需要在'UserControl'中编写脚本。

更清楚 - UserControl中有一个按钮,它应该采用主ResourceDictionary中定义的样式。它应该发生在usercontrol的某个事件上,所以我需要在usercontrol.xaml.cs中编写CS。如果在usercontrol.xaml本身中定义了style,则非常容易。

1 个答案:

答案 0 :(得分:1)

如果它在应用程序资源

SolidColorBrush res =(SolidColorBrush)Application.Current.FindResource(“YellowSolidBrush”);

相关问题