1
我试图设置根Control
元素的风格,我的XAML在外部ResourceDictionary
定义的StaticResource
,但是我收到的错误:设置样式的静态资源的根控制元素
The resource "MyControlStyle" could not be resolved.
<UserControl
...
>
<UserControl.Resources>
<ResourceDictionary Source="..\Styles\MyStyles.xaml" />
</UserControl.Resources>
<UserControl.Style>
<StaticResource ResourceKey="MyControlStyle"/>
</UserControl.Style>
</UserControl>
除了设置XAML文件利用我的控制中的风格,这怎么能实现呢?我希望能够从UserControl
中设置样式,以便我可以在UserControl
的设计师中看到该样式的效果。
您是否正在项目中使用App.xaml,并将MergedDictionaries声明指向您的资源字典以使它们可用于您正在使用的项目?您不需要在UserControl中声明您的资源字典路径来继承样式模板。 –