コンボボックスのポップアップメニューの最初の要素が、の選択したアイテム領域に表示されないのはなぜですか
SelectedItemバインディングを使用する場合、コンボボックスはどうなりますか?それなしでそれは現れていますか?使用する
同じコードselecteditem+selectedindexは問題ありません!
<ComboBox
ItemsSource="{Binding SchoolclassSubjectViewModels}"
SelectedItem="{Binding SelectedSchoolclassSubjectViewModel}"
SelectedIndex="0"
Height="23"
HorizontalAlignment="Left"
Margin="375,13,0,0"
VerticalAlignment="Top"
Width="151">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding SchoolclassName}" />
<TextBlock Text=" " />
<TextBlock Text="{Binding SubjectName}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
私が使用した回避策と同様に:
SchoolclassSubjectViewModels.Add(schoolclassSubjectVM);
SelectedSchoolclassSubjectViewModel = schoolclassSubjectVM;
この:
SelectedItem="{Binding SelectedSchoolclassSubjectViewModel,Mode=TwoWay}"
しかし、実際に機能するはずなので、xamlのみを使用することをお勧めします。