We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Use a single property from the object on an ItemSource as the property to display

Thread ID:





121165 Nov 16,2015 10:12 AM UTC Nov 17,2015 12:37 PM UTC WPF 4
Tags: SfDataGrid
Asked On November 16, 2015 10:12 AM UTC

If I have the following ViewModel:
public class ObjectWrapperViewModel
{ public object SourceObject { get; set; } //An unknown object, generate the table columns. public bool WasProcessed { get; set; } //Used for styling the data grid row. }

Which is bound to the view with:

The resulting view is (which is what I'd expect):

However, is there a way to point the SfDataGrid to the property "SourceObject" as the main property to display in the grid so the result is displayed like it is below but with the highlighting still.

The result should be:
1) The SfDataGrid generates the columns automaticly for any given object.
2) Should still have access to the "
WasProcessed" property (or others) in the ViewModel.

Replied On November 16, 2015 10:14 AM UTC

The view code is:

<Syncfusion:SfDataGrid ItemsSource="{Binding Objects}">
        <Style TargetType="Syncfusion:VirtualizingCellsControl">
                <DataTrigger Binding="{Binding WasProcessed}" Value="True">
                    <Setter Property="Background" Value="#BCFF77"/>
                <DataTrigger Binding="{Binding WasProcessed}" Value="False">
                    <Setter Property="Background" Value="#FF7777"/>

Sivakumar R [Syncfusion]
Replied On November 16, 2015 10:31 AM UTC

Hi Carl,

You can bind inner properties with SfDataGrid by setting MappingName like below, (Complex properties)
<syncfusion:SfDataGrid AutoGenerateColumns="False"
                       ItemsSource="{Binding Objects}">
        <syncfusion:GridTextColumn MappingName="SourceObject.ID" />
        <syncfusion:GridTextColumn MappingName="SourceObject.Name" />
        <syncfusion:GridTextColumn MappingName="SourceObject.Offset" />

Refer below UG link,

It is not possible to autogenerate the columns based on SourceObject as this is inner property. You have to define columns manually as in the above code snippet. You can skip WasProcessed column, by manually defining columns.


Replied On November 16, 2015 10:36 AM UTC

Hello Sivakumar,

I don't know if the object will always have the columns ID, Name and Offset though so I can't simply define the columns in the XAML like you have suggested.

I could generate the columns from code behind but was simply wondering if there was a way to specify an underlying property to bind with to the row instead.


Jai Ganesh S [Syncfusion]
Replied On November 17, 2015 12:37 PM UTC

Hi Carl,

As mentioned in our previous update, you have to specify the columns at runtime to meet your requirement. We don’t have any properties to generate columns based on inner properties of underlying Data.

Jai Ganesh S


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon