MouseDown 在网格中不起作用(仅适用于网格中的按钮)

问题描述 投票:0回答:3
wpf grid wrappanel mousedown
3个回答
18
投票

单独设置 IsHitTestVisible 不会使其工作。

如果“背景”设置为“无”,则元素不可单击。要使其可点击(适用于网格、堆栈面板等),请将背景设置为#00000000。这是一项旨在防止用户点击幽灵按钮的功能。但是,为其指定颜色将使其可点击。


0
投票

尝试在网格上设置 IsHitTestVisible = true


0
投票

在我的固定情况下,对于中间只有一个按钮的 3x3 网格,我在 xaml 中为空行和空列添加了 PreviewMouseDown 事件:

<DataGridCell Grid.Row="0" PreviewMouseDown="EmptyAreaPreviewMouseDown"/>
<DataGridCell Grid.Row="2" PreviewMouseDown="EmptyAreaPreviewMouseDown"/>
<DataGridCell Grid.Column="0" PreviewMouseDown="EmptyAreaPreviewMouseDown"/>
<DataGridCell Grid.Row="2" PreviewMouseDown="EmptyAreaPreviewMouseDown"/>

在代码隐藏中:

private void EmptyAreaPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
    // do here empty area work
}

希望它对将来的人有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.