开发者

WPF event capture. control firing mouseup but not mousedown

I've read a few articles on related issues and this one seems to be inconsistent.

I have a datagrid control in which I need to capture mouse location when the mouse is clicked. I have code to do this in the m开发者_JAVA百科ouseup and mousedown event handlers. mousedown is what I want, but that event is never fired. I put the code there and set a breakpoint and it never reaches that point. the mouseup however does fire just as it should, but its not the event I need and I'm getting unpredictable results.

are there any articles on this to explain what's happening? I assume its some kind of a routed event issue. but why would mouseup work but mousedown not? How can I fix my code so that all the events fire when they should?


The issue is happening because the cells in the datagrid are capturing the MouseDown events. You can try to subscribe to that event in code via:

DataGridName.AddHandler(MouseDownEvent, new MouseButtonEventHandler(DataGridName_MouseDown), true);

Or if that's not what you're wanting to do there's also, I believe, a PreviewMouseDown event that's already assigned to a DataGrid that you can use.

I hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜