C# 在ComboBox.ItemsSource上设置索引已更改

C# 在ComboBox.ItemsSource上设置索引已更改,c#,wpf,data-binding,C#,Wpf,Data Binding,我正在使用绑定设置组合框的ItemsSource。 在没有事件处理程序的情况下,如何将组合框的索引设置为0,或者必须使用事件处理程序 WPF中的SelectedIndex将被忽略,因为SelectedValue已分配给绑定 <ComboBox SelectedValue="{Binding Class}" ItemsSource="{Binding Source={StaticResource classList}}" SelectedIndex=

我正在使用绑定设置组合框的ItemsSource。 在没有事件处理程序的情况下,如何将组合框的索引设置为0,或者必须使用事件处理程序

WPF中的SelectedIndex将被忽略,因为SelectedValue已分配给绑定

<ComboBox SelectedValue="{Binding Class}" 
          ItemsSource="{Binding Source={StaticResource classList}}"
          SelectedIndex="0"/>
<ComboBox SelectedValue="{Binding ItemSubClass}" 
          ItemsSource="{Binding Class.AvailableSubClasses}" 
          SelectedIndex="0"/>


当cb1.value更改时,cb2上的选定值为空。cb1.value在加载时为空。

请显示绑定到ComboBoxNo的代码
SelectedIndex=“0”
应该是您想要的。顺便说一句,显示您的代码!您能否同时显示viewmodel?它仅为cb2设置selectedindex一次,而不为cb1IsSynchronizedWithCurrentItem=“True”修复cb2。但是,从静态方法加载的cb1仍然没有设置为selected。