Obtaining DisplayMemberBinding from DataTemplate

3 posts, 0 answers
  1. David
    David avatar
    4 posts
    Member since:
    Mar 2012

    Posted 26 Mar 2012 Link to this post

    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. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 26 Mar 2012 Link to this post

    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 >>
  3. David
    David avatar
    4 posts
    Member since:
    Mar 2012

    Posted 26 Mar 2012 Link to this post

    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..  
Back to Top