Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2815
Overriding CellValuePresenter used to display IEnumerable property
posted

By default, the xamDataGrid creates child records for a property that is of type IEnumerable.  Instead, I want to ToString() representation of my collection to be represented in a single field.  I tried using the following CellValuePresenter on the field definition:

    <Style x:Key="SimpleCollectionStyle" TargetType="{x:Type igDP:CellValuePresenter}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
                    <Border BorderBrush="{StaticResource DataGridCellOuterBorder}" BorderThickness="1,0,0,0">
                        <TextBlock Text="{Binding DataItem}" Margin="10,5,3,5"   />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
But it did not work.   
Parents
No Data
Reply
  • 30945
    Verified Answer
    Offline posted

    Hello Knji,

     

    Thank you for your post. I have been looking into the appearance that you are trying to achieve and I can suggest using UnboundField, instead of Field. When using Field, its DataType, takes the type of the property, to which the field is bound and if that type is IEnumerable, it displays a hierarchy. The DataType of the UnboundField, by default is string and the ToString will be displayed in the cell of that field, when it is bound to a IEnumerable. Also I can suggest changing the Binding of the Text of the TextBlock, since binding to the DataItem property, it will display the ToString of the object used as data for the record. You can use RelativeSource and bind the Text to the value of the cell. I have created a sample application for you, that shows how you can implement the approach I have described.

     

    Please let me know if you need any further assistance on the matter.

     

    Sincerely,

    Krasimir

    Developer Support Engineer

    Infragistics

    www.infragistics.com/support

    CollectionFieldAsString.zip
Children