MouseDown 在网格中不起作用(仅在网格中的按钮上) [英] MouseDown doesnt work in Grid (only on buttons which in grids)
问题描述
MouseDown 事件有问题.我的应用看起来像这样,我有网格,我在后面的代码中添加按钮
I have problem with MouseDown event. My app looks like that, I have grid in which im adding buttons in code behind
<Grid Grid.Column="1" Name="gridWithButtons" MouseDown="normalModeButtonsWP_MouseDown" >
<WrapPanel Name="normalModeButtonsWP" MouseDown="normalModeButtonsWP_MouseDown" ></WrapPanel>
</Grid>
但是当我在网格/包装面板中按下鼠标按钮时(例如,我的意思是在按钮之间的空白区域)它不起作用.仅在按下包装/网格中的按钮时才有效.有人知道怎么处理吗?
But when im pressing mouse button in grid/wrappanel ( i mean in empty space between buttons for example) it doesnt work. Works only when im pressing button which is in wrap/grid. Anyone know how to handle it?
推荐答案
单独设置 IsHitTestVisible 将无法正常工作.
Setting IsHitTestVisible alone will not make it work.
如果背景设置为无,则元素不可点击.要使其可点击(适用于网格、堆栈面板等),请将背景设置为 #00000000.这更像是一种解决方法,但它可以工作并且看起来很好.
Elements are not clickable if Background is set to None. To make it clickable (applies to grid, stackpanel, etc) set the Background to #00000000. This is more like a workaround however it works and looks fine.
这篇关于MouseDown 在网格中不起作用(仅在网格中的按钮上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!