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