Solved

Silverlight 4, DataGrid Image Column.

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
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…

730 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