Home Forums WPF controls Xceed DataGrid for WPF Can I use a ValueConverter to set a field value based on other fields?

2 sujets de 1 à 2 (sur un total de 2)
  • Auteur
  • jxbma
    Post count: 2
    #50432 |


    I have a WPF XCeed DataGridControl.

    I’m not sure if this entirely possible using a value converter, but I thought I’d ask.

    Consider the following data

    FieldA   FieldB   FieldC   FieldD
    a         b         c       7
    a         b         d       8
    a         b         c       9

    Let’s say a rule exists that says: If FieldC == « d »
    then FieldD displays « Suprise » in the grid.

    There are two approaches to this.
    1) I can filter and massage the data before it gets passed to the DataGridControl
    and apply any rules I want to there.
    2) I implement the rule using a ValueConverter with the DataGridControl

    Is it possible to implement such a solution through WPF using a ValueConverter within the
    XCeed DataGridControl?

    If so, can someone point me to an example?


    Post count: 5

    I wrote some cell template resources to be applied to specific columns. One of which was to take a value that was coming in as an enum and passing it to a value converter to format it into a nice string format. The same should work for you.

    Here’s the template:

            <DataTemplate x:Key="EnumCellTemplate">
                    <TextBlock x:Name="txt"
                            <Style TargetType="{x:Type TextBlock}">
                                <Setter Property="Text"
                                        Value="{Binding Converter={StaticResource EnumStr}}" />

    Then in the Columns definition of the DataGridControl, you just have to define the column and set the CellContentTemplate. Something like:

       <g:Column CellContentTemplate="{StaticResource EnumCellTemplate}" FieldName="MyEnumField" />

    You can use the above to do all kinds of things – not just change d to surprise. For instance, I have another cell template that takes the value and uses that to return an ImageBrush that gets applied to a Canvas so I can display an image based on the value.

2 sujets de 1 à 2 (sur un total de 2)
  • Vous devez être connecté pour répondre à ce sujet.