我有一段代码如下:
ResourceDictionary res = (ResourceDictionary)Application.LoadComponent(new Uri("Style.xaml", UriKind.Relative));
Style style = new Style();
style.Resources = (Style)res["ComboBoxTextBox"];
VS2008返回一个错误:
style.Resources = (样式)res["ComboBoxTextBox"];
(将“Style”翻译为“样式”,因为这更符合中文语境。)
Cannot implicitly convert type 'System.Windows.Style' to 'System.Windows.ResourceDictionary'
我该如何将ResourceDictionary
中的样式正确地分配给控件?