具有负值的 WPF Button ControlTemplate 给出了错误的点击框

WPF Button ControlTemplate with negative values gives wrong clickbox

我有一个用 ControlTemplate 定义的按钮,如下所示:

<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>

当我点击除 + 形状右下角以外的任何地方时,不会触发 ButtonBase_OnClick(以及 ICommand)。

我最终计划在以某个位置为中心的 Canvas 中使用 Button,这就是为什么我需要 ControlTemplate.

中的负值

如何在 ControlTemplate 中保持相同 Shape 的同时触发 ButtonBase_OnClick

编辑:
我尝试按照 中的说明在我的 ControlTemplate 中的 Path 周围放置一个 Grid,但这似乎并没有触发 ButtonClick事件。

将您的路径放入视图框

<Viewbox Width="50" Height="50">
    <Path here...>
</Viewbox>