数据网格模板列中的组合框显示system.data.datarowview

时间:2015-07-10 16:59:40

标签: c# wpf combobox wpfdatagrid datagridtemplatecolumn

在我的项目中,我有一个包含三个组合框模板列的数据网格。并且组合框是使用xaml的数据绑定。但是当我运行项目时,组合框显示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>

为什么它没有显示正确的数据。任何人都可以建议我解决这个问题的方法

1 个答案:

答案 0 :(得分:1)

代码DisplayMemberPath="{Binding CategoriesCollection.Columns[1]}"失败,因为它必须像您提供的ItemsSource绑定一样被赋予相对源绑定。

为Displaymember路径提供正确的绑定

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

或将其硬编码为所寻求的目标属性名称。

相关问题