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

image column

5 Answers 148 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Moshe
Top achievements
Rank 1
Moshe asked on 28 Nov 2010, 08:31 AM

Hi,
I want to use model of image column in such way:

<telerikGrid:GridViewDataColumn.CellTemplate>
       <DataTemplate>
           <StackPanel Orientation="Horizontal">
               <Image Stretch="None"
                      Source="../../Images/User.png"
                      Margin="0,0,5,0" />
               <TextBlock Text="{Binding Name}"
                          VerticalAlignment="Center" />
           </StackPanel>
       </DataTemplate>
   </telerikGrid:GridViewDataColumn.CellTemplate>

But I want to create and fill this column with image source programmatically.
I.e. to fill each row by condition and not always from source "../../Images/User.png".
First row source is "../../Images/User1.png".
Second row source is "../../Images/User2.png" and so on.
Can you give me snippet that implement that?

Thanks in advance,
Moshe Fleidervish

5 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 29 Nov 2010, 12:25 PM
Hi Moshe,


You can create in your custom business object a property that will hold the information about a specified image. Then you can easily reference the template either as a Resource defined in a Resource collection or you can load the xaml markup with a single statement. Attached is a sample application that demonstrates how to use the approaches above.

If you need any further assistance please let me know.

All the best,
Vanya Pavlova
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Moshe
Top achievements
Rank 1
answered on 29 Nov 2010, 12:55 PM

 

 

Hi,
Thanks for your answer and project in it.
I tried to use converter,but it doesn't show something in image column.
What is a reason?
All images are in ClientBin/images. 

Thanks in advance,
Moshe


<telerik:GridViewImageColumn IsReadOnly="True" DataMemberBinding="{Binding Path=PRICE_COLUMNS_STATUS,Converter={StaticResource PriceColumnsStatusToImageConverter1}}" Header="PRICE_COLUMNS_STATUS" />

 

 

 

 

 

public

 

 

object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)

 

{

 

 

string text = value.ToString();

 

 

 

//Get the root path for the XAP

 

 

 

string src = Application.Current.Host.Source.ToString();

 

 

 

//Get the application root, where 'ClientBin' is the known dir where the XAP is

 

 

 

string appRoot = src.Substring(0, src.IndexOf("ClientBin"));

 

 

 

//Create the image / uri

 

 

 

BitmapImage bmp = new BitmapImage();

 

 

 

// assuming that the images are added as a resource

 

 

 

if (text == "1")

 

bmp.UriSource =

 

new Uri(appRoot + "ClientBin/images/1.gif", UriKind.Absolute);

 

 

 

if (text == "2")

 

bmp.UriSource =

 

new Uri(appRoot + "ClientBin/images/2.gif", UriKind.Absolute);

 

 

 

if (text == "3")

 

bmp.UriSource =

 

new Uri(appRoot + "ClientBin/images/3.gif", UriKind.Absolute);

 

 

 

return bmp;

 

}

0
Vanya Pavlova
Telerik team
answered on 29 Nov 2010, 04:31 PM
Hello Moshe,


Silverlight 4 does not support Gif images, you should use png for transparency or jpg/jpeg formats to achieve desired result. In this case what is the ItemSource of your RadGridView? In your IValueConverter you can use your custom code to convert the file to an image. Also I am not quite sure how your code snippet is related to the dynamic column in your first post. GridViewImageColumn is a column that is designed to work with images, from the Convert method I can see that you are trying to examine the value of it to a custom property and return desired image. It could be great if you can send us (via a support ticket) your current project also within some more detailed information about the desired final result.


Sincerely yours,
Vanya Pavlova
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Moshe
Top achievements
Rank 1
answered on 29 Nov 2010, 04:55 PM
Vanya,
Greetings,it works!
Thank you very much.

Moshe
0
Moshe
Top achievements
Rank 1
answered on 30 Nov 2010, 05:09 PM
Hi Telerik Team,
I 'm using GridViewImageColumn with value converter as I writed in previous post.
And I want to make image column sortable.
Property IsSortble for this column doesn't work.
How can I solve this problem?

Thanks,Moshe
 
Tags
GridView
Asked by
Moshe
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Moshe
Top achievements
Rank 1
Share this question
or