开发者

Style BasedOn a user-defined style

I have a DefaultStyle and then another Style defined like this

<Style TargetType="{x:Type my:CustomButton}" BasedOn="{StaticResource DefaultStyle}" x:Key="DefaultCustomButton"> ...

Then, having defined this style, I have

<Style TargetType="{x:Type my:CustomButton}" BasedOn="{StaticResource DefaultCustomButton}" />

No problem, so far.

Now, I wanted to reuse a good part of that second style, so I defined the following:

<Style TargetType="{x:Type my:CustomToggleButton}" BasedOn="{StaticResource DefaultCustomButton}" x:Key="DefaultToggleButton"> ...

and then

<Style TargetType="{x:Type my:CustomToggleButton}" BasedOn="{StaticResource DefaultToggleButton}" />

Finally, I used the new button in a window:

<my:CustomToggleButton x:Name="measurableButton">Text Goes Here</my:CustomToggleButton>

At that point, I get this error:

"Cannot convert the value in attribute 'BasedOn' to object of type 'System.Windows.Style'. Can only base on a Style with target type that is base type 'CustomToggleButton'.

Anything obvious开发者_StackOverflow? Does CustomToggleButton have to derive from CustomButton?


See the note (in yellow down the page a bit) here: http://msdn.microsoft.com/en-us/library/system.windows.style.basedon.aspx

So your CustomToggleButton must derive from CustomButton. I'm assuming (now) based on the error that it does not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜