I have a button defined with a ControlTemplate
like this:
<Button VerticalAlignment="Bottom" HorizontalAlignment="Right" Click="ButtonBase_OnClick">
<Button.Template>
<ControlTemplate TargetType="Button">
<Path Data="M-20,-60L-20,-20 -60,-20 -60,20 -20,20 -20,60 20,60 20,20 60,20 60,-20 20,-20 20,-60z">
<Path.Style>
<Style TargetType="Path">
<Setter Property="Stroke" Value="Red" />
<Setter Property="Fill" Value="Blue" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="StrokeThickness" Value="2" />
</Trigger>
</Style.Triggers>
</Style>
</Path.Style>
</Path>
</ControlTemplate>
</Button.Template>
</Button>
When I click anywhere but the bottom-right part of the +
shape, ButtonBase_OnClick
(and an ICommand
for that matter) isn't triggered.
I eventually plan to use the Button
in a Canvas
centered around a certain location, which is why I need the negative values in the ControlTemplate
.
How can I make it so ButtonBase_OnClick
triggers while maintaining the same Shape
in the ControlTemplate
?
Edit:
I tried placing a Grid
around the Path
in my ControlTemplate
as explained in WPF. Is it possible to do ellipse “rectangle bounds” hittest?, but that doesn't seem to trigger the Button
's Click
event.