一般而言,ComboBox的SelectionChanged事件中都應檢查ComboBox是否被打開,若沒打開則不作任何動作,方法可以參考以下
private void SupplierComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// IsDropDownOpen serves for two purposes here:
// 1. Close the drop down after the user selected a value (It seems like the drop down would not close if a message box is pop up)
// 2. Acts as an indicator for this method to prevent recursion when this method rollbacks a data
if (this.SupplierComboBox.IsDropDownOpen && this.AccessoryGoodsReceive != null && this.AccessoryGoodsReceive.Details != null &&
this.AccessoryGoodsReceive.Details.Count > 0 && e.RemovedItems.Count >= 1 && e.RemovedItems[0] != null)
{
this.SupplierComboBox.IsDropDownOpen = false;
if (MessageBox.Show("Currently mapped APOs will be removed, proceed?", "Change Supplier", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
this.AccessoryGoodsReceive.Details.Clear();
AvailableAccessoryPurchaseOrderDataGrid.ItemsSource = new ObservableCollection<AccessoryGoodsReceiveDetail>();
}
else
{
this.AccessoryGoodsReceive.Supplier = e.RemovedItems[0] as SupplierMaster;
}
}
}
本博客讨论了如何在ComboBox的SelectionChanged事件中检查组件是否打开,并在满足特定条件时清空数据或更改供应商信息。
2929

被折叠的 条评论
为什么被折叠?



