2015-07-10 54 views
0

在我的项目中,我有一个数据网格与三个组合框模板列。并且组合框使用xaml进行数据绑定。但是当我运行项目组合框显示system.data.dataRowView。这是我在数据网格单元数据网格模板列内的组合框显示system.data.datarowview

<DataGridTemplateColumn Header="Category" Width="*" x:Name="categoryColumn"> 
       <DataGridTemplateColumn.CellTemplate> 
        <DataTemplate> 
         <ComboBox x:Name="categoryBox" 
          IsEditable="True" 
          fa:FocusAttacher.Focus="True" 
          controls:TextBoxHelper.ClearTextButton="True" 
          controls:TextBoxHelper.SelectAllOnFocus="True" 
          controls:TextBoxHelper.Watermark="Category" 
          MaxDropDownHeight="125" 
          SelectionChanged="CategoryBox_OnSelectionChanged" 
          IsSynchronizedWithCurrentItem="True" 
          DisplayMemberPath="{Binding CategoriesCollection.Columns[1]}" 
          SelectedValuePath="{Binding CategoriesCollection.Columns[0]}"  
          ItemsSource="{Binding Path=DataContext.CategoriesCollection.DefaultView, 
          RelativeSource={RelativeSource FindAncestor, AncestorType=DataGrid}}" /> 
        </DataTemplate> 
       </DataGridTemplateColumn.CellTemplate> 
      </DataGridTemplateColumn> 

为什么它没有显示正确的数据代码。任何人都可以提出我的方式来解决这个问题

+0

获得的绑定路径摆脱'CategoriesCollection.'为'DisplayMemberPath'和'SelectedValuePath'这应该只是'{绑定路径=列[1]}' –

+0

它不工作 – Sony

+0

你仍在'系统。 data.dataRowView' –

回答

1

代码DisplayMemberPath="{Binding CategoriesCollection.Columns[1]}"失败,因为它已被赋予相对源只是结合作为ItemsSource结合你存在。

要么为Displaymember路径提供适当的结合

{Binding Path=DataContext.CategoriesCollection.Columns[1], 
     RelativeSource={RelativeSource FindAncestor, AncestorType=DataGrid}}"` 

或硬编码它是被寻找的目标属性名称。