MouseDown doesnt work in Grid (only on buttons which in grids)

醉酒当歌 提交于 2019-12-07 01:12:03

问题


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?


回答1:


Setting IsHitTestVisible alone will not make it work.

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.




回答2:


Try setting IsHitTestVisible = true on your grid



来源:https://stackoverflow.com/questions/12669756/mousedown-doesnt-work-in-grid-only-on-buttons-which-in-grids

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!