1

I have written a converter class(implementing IValueConverter) which converts a code that comes from the database (for example "CTY") into a more user friendly description (for example "City"). I want to use the converter on a single Column in my XCeed WPF Datagridcontrol, but I do not know to which property I must set the Converter to. I also tried to attach it to a DataCell using a style but it won't work properly and I think it is also not necessary since the converter should apply to only one column and not every cell.

The columns are also autogenerated so if I could apply it at runtime, that would be awesome!

I don't know to which property of the column I must aplly the converter to (the Xceed Column doens't have a "Binding" property. Do you guys have any suggestions?

More examples or code can be provided if asked for. I hope my problem is a bit clear for you.

EDIT:

This are the things I use in my XAML file:

     <utils:BudgettaireEntiteitConverter x:Key="BudgettaireEntiteitConverter" />

    <xcdg:DataGridCollectionViewSource x:Key="GridViewSourceDefault"
                                               Source="{Binding Converter={StaticResource BudgettaireEntiteitConverter}}">
                <xcdg:DataGridCollectionViewSource.DetailDescriptions>
                        <lc:ActieOverzichtBudgettenDescription  
                                                         RelationName="Budgetten"
                                                         AutoCreateDetailDescriptions="False" 
                                                         AutoCreateForeignKeyDescriptions="False"
                                                         AutoCreateItemProperties="True"
                                                         Title="Budgetten" >
                            <lc:ActieOverzichtBudgettenDescription.StatFunctions>
                                <xcdg:SumFunction ResultPropertyName="SumOfBedragInBudget"
                                              SourcePropertyName="BedragInBudget" />

                                <xcdg:SumFunction ResultPropertyName="SumOfBedragInAfwachting"
                                              SourcePropertyName="BedragInAfwachting" />
                            </lc:ActieOverzichtBudgettenDescription.StatFunctions>

                        <lc:ActieOverzichtBudgettenDescription.DetailDescriptions>
                                <lc:ActieBudgetRegistratieSleutelsDescription RelationName="RegistratieSleutels"
                                                                              AutoCreateDetailDescriptions="False"
                                                                              AutoCreateForeignKeyDescriptions="False"
                                                                              AutoCreateItemProperties="True"
                                                                              Title="Registratiesleutels" />
                </lc:ActieOverzichtBudgettenDescription.DetailDescriptions>

         </lc:ActieOverzichtBudgettenDescription>

   </xcdg:DataGridCollectionViewSource.DetailDescriptions>

</xcdg:DataGridCollectionViewSource>

 <xcdg:DataGridControl x:Name="lsvActies"
                              TargetUpdated="OnListTargetUpdated"
                              ItemsSourceName="Acties" 
                              IsRefreshCommandEnabled="False"
                              rf:XceedGridService.LoadUserSettings="True"
                              rf:XceedGridService.SettingsKeyName="ActieOverzichtGridKey"
                              rf:XceedGridService.ItemContextMenu="{StaticResource ActieContextMenu}">

                <xcdg:DataGridControl.CommandBindings>
                <CommandBinding Command="Delete" Executed="ExecuteDeleteItem" CanExecute="CanExecuteDeleteItem"/>
            </xcdg:DataGridControl.CommandBindings>

        </xcdg:DataGridControl>

This is my Converter:

 Public Class BudgettaireEntiteitConverter
        Implements IValueConverter

        Private hs As Hashtable = FillHashTable()


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

            If hs.ContainsKey(value)
                Return hs(value).ToString()
            Else
                Return Nothing
            End If

        End Function

        Public Function ConvertBack(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
            Throw New NotSupportedException("ConvertBack not supported!")
        End Function

        Function FillHashTable() As Hashtable
            Dim hashtable As New Hashtable
            Dim dataCache = New ReferentieDataCache

            Dim budgettaireEntiteiten = dataCache.GetBudgettaireEntiteiten()

            For Each budgettaireEntiteitRow As BudgettaireEntiteitRow In budgettaireEntiteiten
                hashtable.Add(budgettaireEntiteitRow.BudgettaireEntiteit, budgettaireEntiteitRow.DisplayOmschrijving)
            Next

            Return hashtable
        End Function

    End Class

EDIT2:

I tried with the DataGridItemProperty (see XAML below) but when I debug I do not enter in the Converter class and the grid just loads with the initial data and not with the converted data.

 <xcdg:DataGridCollectionViewSource.ItemProperties>
        <xcdg:DataGridItemProperty Name="BudgettaireEntiteit" Converter="{StaticResource BudgettaireEntiteitConverter}" />
 </xcdg:DataGridCollectionViewSource.ItemProperties>

It definitely knows the BudgettaireEntiteit field because if I enter a field that doesn't exist it throws an error. Now it just does nothing

4

2 回答 2

5

您可以将 DataGridCollectionViewSource 与DataGridItemProperty一起使用。此对象有一个Converter属性,可用于将您创建的转换器分配给所需的列。

就像是:

 <xcdg:DataGridItemProperty Name="RequiredColumn"
       Converter="{StaticResource BudgettaireEntiteitConverter}"/>

超出文档中的更详细示例。

于 2012-01-20T10:13:58.457 回答
0

完整的示例代码如下。此 XAML 将 DateConverter 应用于 Xceed 网格中的两个日期列(DateDue 和 DatePaid):

<Window.Resources>
    <local:DateConverter x:Key="conDate" />
    <xcdg:DataGridCollectionViewSource
        AutoCreateItemProperties="False"
        Filter="Filter_By_Member"
        x:Key="cvsDonations">
        <xcdg:DataGridCollectionViewSource.ItemProperties>
            <xcdg:DataGridItemProperty
                Name="DateDue"
                Converter="{StaticResource conDate}">
            </xcdg:DataGridItemProperty>
            <xcdg:DataGridItemProperty
                Name="DatePaid"
                Converter="{StaticResource conDate}">
            </xcdg:DataGridItemProperty>
        </xcdg:DataGridCollectionViewSource.ItemProperties>
    (</xcdg:DataGridCollectionViewSource>

.....

</Window.Resources>
于 2018-04-15T23:09:17.637 回答