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中聲明您的資源字典路徑來繼承樣式模板。 –