Solved

Silverlight 4, DataGrid Image Column.

Posted on 2011-09-13
2
859 Views
Last Modified: 2013-12-17
I am using TelerikRadGridview, but I think there is not much difference for my desire.

.XAML:
 
<telerik:RadGridView Margin="22,77,25,0" Name="radGridView1" VerticalAlignment="Top" Height="450" telerik:Theming.Theme="Windows7" CanUserReorderColumns="True">


            <telerik:RadGridView.Columns>
                <telerik:GridViewColumn Header="ImageDisplay">
                    <telerik:GridViewColumn.CellTemplate>
                        <DataTemplate x:Name="dtTemp">
                            <Image x:Name="ImageDisplay2"/>
                        </DataTemplate>
                    </telerik:GridViewColumn.CellTemplate>
                </telerik:GridViewColumn>
            </telerik:RadGridView.Columns>

Open in new window


.CS
 
DomainService1 DS1 = new DomainService1();
            radGridView1.ItemsSource = DS1.Descriptions;
            DS1.Load(DS1.GetDescriptionsQuery());

Open in new window


I want to display Image Column in RadGridview, with URL from the SQL Database.
How can I set Source for this code:

<DataTemplate x:Name="dtTemp">
                            <Image x:Name="ImageDisplay2" Source = HowToSetThisFromDatabase/>
                        </DataTemplate>

Open in new window



The data is binded by using DomainService.


Please help me this problem.
0
Comment
Question by:JameMeck
2 Comments
 
LVL 18

Accepted Solution

by:
Dennis Aries earned 500 total points
ID: 36529448
A nice way is to use a converter that takes your URL and returns the image for you.
Check out the article at the DotNetCurry.

Taken from the code in that article (converts stream to image).
public class ImageConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            MemoryStream memStream = new MemoryStream((byte[])value,false);
            BitmapImage empImage = new BitmapImage();
            empImage.SetSource(memStream);
            return empImage; 
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

Open in new window


Code can be easily modified to take an URL, read the data as a stream and convert that to the image you need.
0
 

Author Closing Comment

by:JameMeck
ID: 36558037
Thanks! I got it.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now