我有一个DefaultStyle,然后是另一个像这样定义的Style
<Style TargetType="{x:Type my:CustomButton}" BasedOn="{StaticResource DefaultStyle}" x:Key="DefaultCustomButton"> ...
然后,定义了这种风格,我有
<Style TargetType="{x:Type my:CustomButton}" BasedOn="{StaticResource DefaultCustomButton}" />
到目前为止没问题。
现在,我想重用第二种风格的一部分,所以我定义了以下内容:
<Style TargetType="{x:Type my:CustomToggleButton}" BasedOn="{StaticResource DefaultCustomButton}" x:Key="DefaultToggleButton"> ...
然后
<Style TargetType="{x:Type my:CustomToggleButton}" BasedOn="{StaticResource DefaultToggleButton}" />
最后,我在窗口中使用了新按钮:
<my:CustomToggleButton x:Name="measurableButton">Text Goes Here</my:CustomToggleButton>
此时,我收到此错误:
“无法将属性'BasedOn'中的值转换为类型的对象 'System.Windows.Style'。只能基于具有目标类型的Style 这是基本类型'CustomToggleButton'。
有什么明显的吗? CustomToggleButton是否必须从CustomButton派生?
答案 0 :(得分:1)
请在此处查看备注(在页面中以黄色显示):http://msdn.microsoft.com/en-us/library/system.windows.style.basedon.aspx
因此,CustomToggleButton
必须来自CustomButton
。我假设(现在)基于它没有的错误。