为什么SelectionChanged
事件调用3次(第一次 - 当我点击ComboBox
字段时,第二次 - 当我选择ComboBox
中的相应字段时,第三次 - 当我离开时ComboBox
)以及在combobox
中选择相应字段时如何调用它们一次?
XAML:
<DataGridComboBoxColumn x:Name="DGKontynent" Header="Kontynent" Width="120" CanUserSort="False" SelectedItemBinding="{Binding Kontynent}" >
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<EventSetter Event="SelectionChanged" Handler="ContinentSelectionChanged" />
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
C#:
List<string> l3 = new List<string>();
private void ContinentSelectionChanged(object sender, SelectionChangedEventArgs e)
{
string kontynent = null;
l4.Clear();
var row = ZdarzeniaDataGrid.GetSelectedRow();
DataGridCell cell = ZdarzeniaDataGrid.GetCell(row, 5);
if (cell != null)
{
ComboBox combo = GetVisualChild<ComboBox>(cell);
if (combo != null)
{
if (combo.SelectedValue != null)
kontynent = combo.SelectedValue.ToString();
else
return;
}
}
l3 = FK.kraj_wybierz(kontynent, DGKraj);
DataGridCell cell3 = ZdarzeniaDataGrid.GetCell(row, 6);
if (cell3 != null)
{
ComboBox combo3 = GetVisualChild<ComboBox>(cell3);
if (combo3 != null)
{
combo3.ItemsSource = l3;
}
}
}