This is a migrated thread and some comments may be shown as answers.

Obtaining DisplayMemberBinding from DataTemplate

2 Answers 139 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 26 Mar 2012, 11:50 AM
Hi All,

We are using the grid view and we are dynamically generating columns based on some metadata.  In the code I specify the DisplayMemberBinding and when the grid renders the columns display the correct data.  Now I need to extend the UI so that when the meta data says a column is of a specific type I need to apply a different cell template.  So I have code that does this.

column.CellTemplate = ResolveTemplate()

This returns a specifc DataTemplate that I have defined and is shown below. 

    <DataTemplate x:Key="DefaultTextCellTemplate">
        <Grid Presentation:SharedResourceDictionary.UsesImplicit="True">
            <TextBlock Text="{Binding}"
                       Foreground="Blue" />
        </Grid>
    </DataTemplate>

The problem I have is that the binding is the row data not the DisplayMemberBinding I have specified.  I need to get the value for the column the same way the default cell style does but I cannot figure out how you guys have done this.  A look in the styles didn't answer it. 

Could you tell me if this is possible and how I may go about solving this problem using the GridView.

Many Thanks,

Dave Hanson

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 26 Mar 2012, 01:12 PM
Hi Dave,

 Maybe it will be better in your case to create custom column and reuse it where needed. You can override CreateCellElement and return desired component(s) or load a template.

Please check this demo for more info about custom columns. 

Regards,
Vlad
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
David
Top achievements
Rank 1
answered on 26 Mar 2012, 01:21 PM
Yes this is the approachI have taken.  Basically I have subclassed the GridViewDataColumn and then overriding the CreateCellElement loading the datatemplate using LoadContent then I apply the dataContext to to the root element. Seems to work..  
Tags
GridView
Asked by
David
Top achievements
Rank 1
Answers by
Vlad
Telerik team
David
Top achievements
Rank 1
Share this question
or