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

[Solved] binding to DataMemberBinding in CellTemplate

3 Answers 392 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Hicham
Top achievements
Rank 1
Hicham asked on 11 Jan 2011, 10:33 PM
Hi,
I have a very simple question:
how to tell silverlight to bind with the DataMemberBinding as a source in a CellTemplate?
I had put the following in a xaml:
    <my:MyGridCol.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Name}" />
        </DataTemplate>
    </my:MyGridCol.CellTemplate>
The problem is that "Name" is relative to the current row object and not the value of the DataMemberBinding for that object.
How can I tell silverlight to bind to the value of the DataMemberBinding?
Thank you.

3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 12 Jan 2011, 05:07 PM
Hi Hicham,

This is how it works - if the gridview is bound to a collection of Employees for example, each column is bound to a property of the Employees class. So, if the Name is a property of the class - there should be no problem to bind to it.
What is your exact case?

Greetings,
Veselin Vasilev
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Hicham
Top achievements
Rank 1
answered on 17 Jan 2011, 11:22 PM
Hi,
In my Application all business objects implement a Name property.
I encapsulated in a class an 'Object Column'. In the xaml for a grid I just declare somthing like <my:ObjectGridColumn ObjecType="DotNet Type..." DataMemberBinding="..."/>
DataMemberBinding is bound to a property that provides an object of that same type...

I would like the ObjectGridColumn to implement some generic scenarios:
* display the name of the object
* allows editing with a combo displaying all available objects
* have some navigation to edit the object
* ...etc.
What I tried is to display the name using something like
 <my:MyGridCol.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Name}" />
        </DataTemplate>
    </my:MyGridCol.CellTemplate>

But this does not work since Name is looked for on the object that is bound to the row which I do not know...
What I was looking for is a technique to tell the CellTemplate to bind to the DataMemberBinding object.

If this is not possible. how you would implement such a generic column?
Thank you.
Hicham.
0
Vlad
Telerik team
answered on 18 Jan 2011, 08:22 AM
Hello,

 You can check CellValueBindingBehavior in this blog post for more info. 

Best wishes,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
GridView
Asked by
Hicham
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Hicham
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or