【发布时间】:2011-02-27 00:21:24
【问题描述】:
为什么我的组合框弹出菜单中的第一个元素没有显示在所选项目区域中
我的组合框,当我使用 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 的方式,因为它应该真的可以工作。
【问题讨论】:
标签: wpf combobox selecteditem selectedindex