1

我有一个带有 ComboboxEdit CellTemplate 的两列的 Devexpress DxGrid

<dxg:GridControl Name="grid">
    <dxg:GridControl.Columns>
       <dxg:GridColumn FieldName="Size_ID" CellTemplate="{DynamicResource DimensionComboBox}"/>
       <dxg:GridColumn FieldName="Color_ID" CellTemplate="{DynamicResource DimensionComboBox}"/>
    </dxg:GridControl.Columns>
</dxg:GridControl>

在我的 app.xaml 我定义了一个模板

<DataTemplate x:Key="DimensionComboBox" >
                <dxe:ComboBoxEdit x:Name="PART_Editor"  DisplayMember="Grp_Property_Desc" ValueMember="Grp_Property_ID" >
                    <dxe:ComboBoxEdit.ItemsSource>
                        <Binding Path="Data">
                            <Binding.Converter>
                                <local:GridComboBoxItemSourceConverter/>
                            </Binding.Converter>
                        </Binding>
                    </dxe:ComboBoxEdit.ItemsSource>
                </dxe:ComboBoxEdit>
            </DataTemplate>

我想知道转换器中的列字段名称,以便我根据调用转换器的列返回数据

Public Class GridComboBoxItemSourceConverter
    Implements IValueConverter

#Region "IValueConverter Members"

    Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert

'if field name is color_id then return data for color_id

'if field name is size_id then return data for size_id

    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
        Throw New NotImplementedException()
    End Function
#End Region
End Class

有没有一种方法可以在不必为每一列创建转换器类的情况下完成此操作,我确实有许多其他列要转换。

4

1 回答 1

1

您可以为每列创建一个数据模板并在转换器参数中指定列名

于 2013-01-10T09:31:25.863 回答