我有一个DataGrid
列ComboBox
,只有在获得焦点时才需要向该组合框添加项目。我处理事件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;
}
}
}