Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit How to add an image column to a bound datagrid when the image has to be generated based on a datavalue of a column?
3 replies. Latest Post by sladapter on April 24, 2008.
(0)
ymo519
Member
20 points
10 Posts
04-23-2008 7:33 AM |
I have a datagrid which uses a wcf serrvice to get populated.
datagrid.itemssource = e.Result;
Now i have to modify the data of column of int datatype into images based on the values.
For Example: If r = 1, show correct icon else show wrong Icon.
This should be done at run-time.
If there is some sample code, it would be helpful..
Thank You
JKewley
14 points
3 Posts
04-23-2008 2:01 PM |
Try this:http://silverlight.net/forums/t/14714.aspx
based upon this:http://silverlight.net/forums/p/11614/38274.aspx
04-24-2008 12:38 AM |
Can i know how did u set the datacontext?
Is the Datacontext for the particular column mentioned ur post generated from a WCF service?
My datagrid is populated from a WCF service.
I am not able to set the datacontext for particular column.
sladapter
All-Star
17427 points
3,171 Posts
04-24-2008 12:20 PM |
I assume the return value (e.Result) from your WCF call is a list object (or a object Array)? When you set the DataGrid.ItemSource = e.Result, each UIElement in the DataGrid will automatically has a DataContext set which is the Data Object for that particular row. So you can access to it.
If you set a Image control for a column in the Data Template. You hook up a Loaded event handler for it. On Loaded event handler , you get the Data for that Row, do some checking then set the Image.Source accordingly:
private void Image_Loaded(object sender, RoutedEventArgs e) { Image i = sender as Image; MyDataObject d = i.DataContext as MyDataObject;
if(MyDataObject.Field1 == "something")
{ i.Source = ImageURL;
} }