简体   繁体   中英

WPF: How do I handle mouse click on a Listview inside of a Button?

I have a listview for displaying a table inside of a button. I have a click event assigned to the button, but when the user clicks on the list view, a row is selected on the list view and the mouse click is never bubbled up to the button.

I'm stuck at this point, and need a way to solve this. All the examples I've seen online are for placing a button inside the listview. How do I make this work?

样本截图

Set the IsHitTestVisible property to false on your ListView . Since it is a control that normally processes click events, doing this will have it ignore them.

If you don't want the items to be selectable in the first place, you could make the List View unable to receive Focus. Just set the Focusable property to false .

With the List View unable to receive focus, then I would expect the mouse event to bubble up to the button.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM