为什么我的组合框弹出菜单中的第一个元素未显示在的选定项目区域中
我的组合框,当我使用 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 唯一的方式,因为它应该真的有效。