在下拉弹出窗口中更改选择时,取消组合框的SelectedChanged事件。 [英] Cancel SelectedChanged event of combobox when change selection in the dropdown popup.

查看:151
本文介绍了在下拉弹出窗口中更改选择时,取消组合框的SelectedChanged事件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我通过箭头键更改下拉框中的选择时,会触发SelectionChanged。 


我想在用户选择一个项目时触发此事件列表和下拉列表弹出窗口已关闭。


当下拉框打开并使用箭头键时,如何取消SelectionChanged事件。

解决方案

< blockquote>

您可以制作自己的自定义控件,该控件继承自ComboBox(或您正在使用的任何内容)。在该类的构造函数中,为SelectionChanged添加事件处理程序,并在
弹出窗口打开时通过设置e.Handled = true来标记事件处理。虽然这不会阻止事件向上传播调用树,但它将阻止其他处理程序触发,除非它们明确地订阅"处理"状态。事件(往往很少见)。


您可能需要在自定义控件中处理您正在订阅/标记的事件,以使事情的行为与您完全一致想。祝你好运!


Hi, when i change selection in the dropdown popup by arrow keys, SelectionChanged is fired. 

I want to fire this event when user choose one item in the list and dropdown popup is closed.

How can I cancel SelectionChanged event when dropdown popup is open and using arrow keys.

解决方案

You could make your own custom control that inherits from ComboBox (or whatever you happen to be using). In the constructor for that class, add an event hander for SelectionChanged and mark the event as handled by setting e.Handled = true when your popup is open. While that won't prevent the event from propagating up the call tree, it will stop other handlers from firing unless they explicitly subscribe to "handled" events (which tends to be rare).

You may have to play around with which events you're subscribing to/marking as handled in your custom control to get things behaving exactly the way you want. Good luck!


这篇关于在下拉弹出窗口中更改选择时,取消组合框的SelectedChanged事件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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