WPF 列表视图列标题单击事件
我在 WPF 中有一个 ListView (GridView),我试图根据 http://msdn.microsoft.com/en-us/library/ms745786.aspx。就我而言,其中一列的单元格模板包含一个扩展器。现在,当我单击扩展器标题时,将触发 GridViewColumnHeader.Click 事件。我该如何防止这种情况发生?
I have a ListView (GridView) in WPF and I'm trying to implement sorting according to http://msdn.microsoft.com/en-us/library/ms745786.aspx. In my case, the celltemplate for one of the columns contains an Expander. Now when I click the expander header, the GridViewColumnHeader.Click event fires. How do I prevent this from happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不需要发生任何事情,请使用
e.Cancel = true
取消它。我在我的项目中有类似的东西,我不希望用户对列重新排序:然后,在 XAML 中,我有:
这是 WPF Toolkit 数据网格,但是
e.Cancel = true
应该适用于任何控件。如果用户单击此标题时需要发生其他事情,您也可以在该方法中处理。
如果您需要以不同方式处理这些情况,您可以检查发件人以查看用户单击的位置(在扩展器上或在 gridview 标题上)。如果发送者是扩展器,则取消它。如果发送者是gridview header,则让排序继续。
If nothing needs to happen, cancel it with
e.Cancel = true
. I have something like that in a project of mine, where I don't want the user to reorder the columns:Then, in the XAML, I have:
This is the WPF Toolkit datagrid, but the
e.Cancel = true
should work for any control.If other things need to happen when the user clicks this header, you can also handle it in that method.
You could check the sender to see where the user clicked (on the expander or on the gridview header) if you need to handle these cases differently. If the sender is the expander, cancel it. If the sender is the gridview header, let the sorting continue.