2013-05-13 30 views
0

我有一个编辑客户窗口。用户输入的所有字段都显示在此窗口中。我也有一个性别字段,这是一个组合框。这个组合框的项目必须从表格t_Geslacht填充。表格t_Geslacht的ID和性别列已加入。在这个窗口中,用户可以使用collectionview浏览记录。当我将组合框绑定到性别表时,我会得到这些值。但是,当用户浏览记录时,该值不会改变。在combobox中填写项目限制到collectionviewsource

这里是我的组合框的XAML:

<ComboBox x:Name="geslachtComboBox1" Grid.Column="1" DisplayMemberPath="Geslacht" 
      HorizontalAlignment="Left" Height="22" 
      ItemsSource="{Binding Source={StaticResource lut_GeslachtViewSource}}" 
      SelectedValuePath="GeslachtID" Margin="10.2,5,0,5" Grid.Row="0" 
      VerticalAlignment="Center" Width="120"> 
    <ComboBox.ItemsPanel> 
     <ItemsPanelTemplate> 
     <VirtualizingStackPanel/> 
     </ItemsPanelTemplate> 
    </ComboBox.ItemsPanel> 
</ComboBox> 

下面是收集代码:

customersViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("t_KlantenViewSource"))); 
System.Data.Objects.ObjectQuery<AOV.t_Klanten> customersQuery = this.Getlt_KlantenQuery(aoventities); 
customersViewSource.Source = customersQuery.Execute(System.Data.Objects.MergeOption.AppendOnly); 

我在做什么错?对不起,如果我没有提供足够的信息。

回答

0

您需要将组合框SelectedValue属性绑定到Customer的“GenderID”属性。

<ComboBox x:Name="geslachtComboBox1" Grid.Column="1" 
      DisplayMemberPath="Geslacht"  
      ItemsSource="{Binding Source={StaticResource lut_GeslachtViewSource}}" SelectedValuePath="GeslachtID" 
      SelectedValue="{Binding GenderID}"... //change to the property name for Gender in customer object.. 
+0

非常感谢你Jure!保存了我的一天。 – 2013-05-13 16:57:49