单击空白区域时如何处理事件? [英] How to handle the event when click on empty space?

查看:29
本文介绍了单击空白区域时如何处理事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在列表视图左键单击空白区域时捕捉事件 - 即单击列表视图控件中的任何项目.

I want to catch the event when a listview is left-clicked on an empty space - i.e. clicking on no item within the listview control.

我在列表视图的事件列表中进行了搜索,但没有找到.我怎样才能做到这一点?请帮忙!

I've search in the Events list of the listview but found none. How can I do this? Please help!

如果我能捕捉到这个事件,我想做什么:取消选择列表视图中的所有项目.

What I want to do if I could catch this event: Deselect all items in the listview.

推荐答案

如果将处理程序附加到 ListView 上的 MouseLeftButtonDown 事件,它只会在单击 ListViewItem 之外的区域时触发.项目内的任何点击都将由项目本身处理以驱动 ListView 的选择行为.

If you attach a handler to the MouseLeftButtonDown event on the ListView it will only fire when areas outside of a ListViewItem are clicked. Any clicks inside the items will be handled by the items themselves to drive the ListView's selection behavior.

您可以通过在 ListView 上设置 ItemContainerStyle 来调整背景({x:Null} 不可点击,其他任何内容)和 ListViewItems 的边距来更改可点击区域.还要确保您没有在 ListView 本身上使用空背景(白色是默认设置,透明也可以使用).

You can make changes to the clickable areas by adjusting the Background ({x:Null} is not clickable, anything else is) and Margin of the ListViewItems by setting an ItemContainerStyle on the ListView. Also make sure that you are not using a null Background on the ListView itself (White is the default, Transparent works too).

这篇关于单击空白区域时如何处理事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆