开发者

WPF reading Style from ResourceDictionary to Control in C# code

开发者 https://www.devze.com 2022-12-13 21:46 出处:网络
I have code that looks like below: ResourceDictionary res = (ResourceDictionary)Application.LoadComponent(new Uri(\"Style.xaml\", UriKind.Relative));

I have code that looks like below:

ResourceDictionary res = (ResourceDictionary)Application.LoadComponent(new Uri("Style.xaml", UriKind.Relative));
Style style = new Style();
style.Resources = (Style)res["ComboBoxTextBox"];

VS2008 retuns an error:

style.Resources = (Style)res["ComboBoxTextBox"];

Cannot implicitly convert type 'System.Windows.Style' 开发者_运维知识库to 'System.Windows.ResourceDictionary'

How I can properly assign a style from ResourceDictionary to control?


it should be as easy as

myControl.Style =  (Style)res["ComboBoxTextBox"];
0

精彩评论

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