Solved

Silverlight 4, DataGrid Image Column.

Posted on 2011-09-13
2
863 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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