WPF: Style based on another one in a separate assembly

蓝咒 提交于 2019-11-29 11:14:44

问题


Assembly A - ResourceDictionary contains StyleA style.
Assembly B - ResourceDictionary.MergedDictionaries to merge resources from Assembly A into B.

I would like to create a style in Assembly B "based on" StyleA. Is it possible?

I am trying to create this style:

<Style x:Key="StyleB" BasedOn="{StaticResource StyleA}">
   <Setter Property="Button.Foreground" Value="Khaki"/>
</Style>

But I get a XamlParseException exception at run-time, if I use StyleB:

Cannot convert the value in attribute 'Style' to object of type 'System.Windows.Style'. Can only base on a Style with target type that is base type 'IFrameworkInputElement'. Error at object 'System.Windows.Controls.Button' in markup file 'SamSeekApp;component/mainwindow.xaml'


回答1:


Try adding TargetType="{x:Type Button}" to your 'StyleB'.



来源:https://stackoverflow.com/questions/703206/wpf-style-based-on-another-one-in-a-separate-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!