我有一個DefaultStyle,然後像這樣樣式支持算法FMP一個用戶定義的樣式
<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>
在這一點上,我得到這個錯誤:
"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'.
什麼都明顯? CustomToggleButton是否必須從CustomButton派生?
你說得對。感謝您的鏈接。 –