2009-12-15 72 views
3

我有代码看起来像下面:WPF读样式在C#代码控制

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

VS2008 retuns一个错误:

style.Resources =(样式)RES [“ComboBoxTextBox “];

Cannot implicitly convert type 'System.Windows.Style' to 'System.Windows.ResourceDictionary' 

如何正确指定从ResourceDictionary的样式来控制?

回答

3

它应该是那么容易,因为

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

是啊,我只是做了简单的错误:)悠着点今天:d THX求助 – Kamilos 2009-12-15 12:43:52