I know that there must be an easy answer for this, but I cannot find it.
I have a HoverButton button HoverButton .
<Style x:Key="HoverButton" TargetType="Button"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border> <ContentPresenter/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="BorderBrush" Value="Black"/> <Setter Property="Background" Value="WhiteSmoke"/> <Setter Property="Foreground" Value="DarkRed"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="BorderBrush" Value="Transparent"/> <Setter Property="Background" Value="Transparent"/> </Style>
Then I want to create another "derived" style based on a HoverButton with specific content. I have reduced the complexity of the above style here, but it is complex enough that I do not want to copy and paste it.
<Style x:Key="CloseButton" BasedOn="{StaticResource HoverButton}" TargetType="{x:Type Button}"> <Setter Property="Content"> <Setter.Value> <Path Width="8" Height="8" Stroke="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType=Button}}" Data="M0,0 L8,8 M8,0 L0,8" StrokeThickness="2" /> </Setter.Value> </Setter> </Style>
This does not work. "The specified element is already a logical child of another element. First disable it." It seems I need to override the Template property of the derived style, but somehow refer to the base style template.
Any ideas?
source share