WPF ComboBox GotFocus

时间:2016-08-16 09:51:34

标签: c# wpf

我有一个DataGridComboBox,只有在获得焦点时才需要向该组合框添加项目。我处理事件GotFocus,但仍有问题。事实上,一旦我从下拉列表中选择了一个项目,该事件将再次触发。有关如何解决此问题的任何解决方法。

private void CmbxGotFocus(object sender, RoutedEventArgs e)
{
    if (e.OriginalSource.GetType() != typeof(ComboBoxItem) && !this.returnedFocus)
    {
        //dowork
    }
}

private void CmbxLostFocus(object sender, RoutedEventArgs e)
{
    if (e.OriginalSource.GetType() != typeof(ComboBoxItem))
    {
        ComboBox cb = sender as ComboBox;           

        if (cb != null)
        {
            this.returnedFocus = cb.IsDropDownOpen;
        }
    }
}

0 个答案:

没有答案