I am trying to find a solution to reuse code in XAML for in WPF: I have 3 buttons that have very similar styles, with the only difference being the BorderThickness. They all have a style trigger set that if the user moves the mouse over them, the BorderThickness is set to 1.
<Button Width="50" Height="50" BorderBrush="#66CCFF" >
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="BorderThickness" Value="0,0,0,1" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderThickness" Value="1"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
<Image Margin="12" Source="picture1.png"/>
</Button>
<Button Width="50" Height="50" BorderBrush="#66CCFF">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="BorderThickness" Value="0,1,0,1" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderThickness" Value="1"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
<Image Margin="12" Source="picture2.png"/>
</Button>
<Button Width="50" Height="50"BorderBrush="#66CCFF">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="BorderThickness" Value="1,0,1,1" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderThickness" Value="1"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
<Image Margin="12" Source="picture3.png"/>
</Button>
Since the styles are practically identical apart from the BorderThickness that is applied when the IsMouseOver is false I would like to remove code duplicates and have some sort of Style in a ResourceDictionary where I can specify the initial BorderThickness as a parameter (or something along the lines) and the rest is the same.
I tried to move the BorderThickness="p,q,r,s" part to the <Button ...> tag, but then the style does not get applied when I mouse over (my assumption is that there's a hierarchy between them).
Style inheritanceis not sufficient? - Stefan