判断 Selector.SelectionChanged 事件是否由用户发起 [英] Determine whether Selector.SelectionChanged event was initiated by a user

查看:30
本文介绍了判断 Selector.SelectionChanged 事件是否由用户发起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以确定 Selector.SelectionChanged 事件是由用户发起还是以编程方式发起?

Is it possible to determine whether a Selector.SelectionChanged event was initiated by the user or programmatically?

即我需要类似布尔 "IsUserInitiated" 属性的东西,只有当 SelectionChanged 事件被引发时才为真,因为用户使用鼠标或键盘更改了选择.

I.e. I need something like a boolean "IsUserInitiated" property that is true only if the SelectionChanged event was raised because the user changed the selection using mouse or keyboard.

推荐答案

这应该适用于大多数情况:

This should work in most scenarios:

private void cboStatus_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (this.cboStatus.IsDropDownOpen)
    {
        //OPTIONAL:
        //Causes the combobox selection changed to not be fired again if anything
        //in the function below changes the selection (as in my weird case)
        this.cboStatus.IsDropDownOpen = false;

        //now put the code you want to fire when a user selects an option here
    }
}

这篇关于判断 Selector.SelectionChanged 事件是否由用户发起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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