WPF:基于单独程序集中的另一个样式 [英] WPF: Style based on another one in a separate assembly

查看:63
本文介绍了WPF:基于单独程序集中的另一个样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Assembly A - ResourceDictionary 包含 StyleA 样式.
程序集 B - ResourceDictionary.MergedDictionaries 将资源从程序集 A 合并到 B.

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

我想在基于"StyleA 的Assembly 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>

但我在运行时收到 XamlParseException 异常,如果我使用 StyleB:

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

无法将属性Style"中的值转换为System.Windows.Style"类型的对象.只能基于具有基本类型IFrameworkInputElement"的目标类型的样式.标记文件SamSeekApp;component/mainwindow.xaml"中的对象System.Windows.Controls.Button"出错

推荐答案

尝试将 TargetType="{x:Type Button}" 添加到您的StyleB".

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

这篇关于WPF:基于单独程序集中的另一个样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆