【问题标题】:Combo box inside Data grid template column is showing system.data.datarowview数据网格模板列内的组合框显示 system.data.datarowview
【发布时间】:2015-09-29 12:50:12
【问题描述】:

在我的项目中,我有一个包含三个组合框模板列的数据网格。组合框是使用 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>

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

【问题讨论】:

  • 去掉DisplayMemberPathSelectedValuePath绑定路径中的CategoriesCollection.应该是{Binding Path=Columns[1]}
  • 你还在收到system.data.dataRowView
  • 是的,没有任何改变

标签: c# wpf combobox wpfdatagrid datagridtemplatecolumn


【解决方案1】:

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

为 Displaymember 路径提供适当的绑定

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

或将其硬编码为要查找的目标属性名称。

【讨论】:

    猜你喜欢
    • 2015-11-22
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-27
    相关资源
    最近更新 更多