1
爲什麼我的組合框彈出菜單中的第一個元素在所選項目區域未顯示WPF:與selecteditem設置的組合框不使用SelectedIndex = 0?
我的組合框,當我使用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唯一途徑,因爲它應該真正發揮作用。
我使用sqlite數據庫與SQL純沒有ORM。 第一段聽起來很混亂XD。 你說的不是真的,也許......,因爲我只是在我的代碼這個發現: <組合框 的SelectedItem = 「{結合SelectedSchoolclass}」 的SelectedIndex = 「0」 的DisplayMemberPath = 「SchoolclassName」 的ItemsSource =「{Binding Schoolclasses}」 /> viewmodel中的綁定與上述代碼中的模式相同。不同之處在於我沒有特別定義的ComboBox itemtemplate。 – msfanboy 2010-06-02 20:17:29