当我们在WPF中更改组合框的值时,为什么ComboBox SelectionChanged
事件会触发?
<telerik:RadComboBox Name="onClockComboBox" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Width="200" Height="30" StaysOpenOnEdit="True" IsSynchronizedWithCurrentItem="True" OpenDropDownOnFocus="True"
ItemsSource="{Binding TravelOtherModel.OnClockOptionListCollection,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center"
DisplayMemberPath="OptionName" SelectedValuePath="RowNo" IsFilteringEnabled="True" IsEditable="True" Margin="80,3,0,0">
<ie:Interaction.Triggers>
<ie:EventTrigger EventName="SelectionChanged">
<ie:InvokeCommandAction Command="{Binding OnClockComboBoxSelectedItemChangedCommand}" CommandParameter="{Binding ElementName=onClockComboBox}" >
</ie:InvokeCommandAction>
</ie:EventTrigger>
</ie:Interaction.Triggers>
</telerik:RadComboBox>
SelectionChanged
事件代码是 -
public void OnClockComboBoxSelectedItemChangedCommand_Event(object obj)
{
try
{
RadComboBox onClockComboBox = obj as RadComboBox;
var item = onClockComboBox.SelectedItem as OnClockOption;
string s= onClockComboBox.SelectedValue.ToString();
onClockComboBox.SelectedValue = "0";
}
catch (Exception ex)
{
}
}
当我们通过以下代码设置默认选择值时,它再次触发SelectionChanged
事件为什么?
onClockComboBox.SelectedValue = "0";
答案 0 :(得分:1)
当我们设置默认值时,请选择&#39;通过下面的代码值然后再次触发 选择改变了事件的原因?
因为它应该,否则如果组合框被重置,你将如何得到通知。假设您选择的值必然会加载一些其他控件。即使是默认值,也需要知道选择是否已经改变。