WPF reading Style from ResourceDictionary to Control in C# code
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"];
精彩评论