Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Image in silverlight datagrid

Posted on 2008-11-17
1
Medium Priority
?
9,615 Views
Last Modified: 2013-12-17
I'm a Siliverlight newbie.

I want to create a datagrid with a different photo for each row.  These photos will reside in the c:\Photos\xxx\ directory on the web server, where xxx represents a unique ID for each data row.

This xaml works, where I've just used a test file for the photo:

                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image x:Name ="TestImage" Source ="100_0117.JPG" Height ="50"/>
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>

But what is the syntax to make that image path vary for each row?

Thanks.
0
Comment
Question by:ReeseWatt
1 Comment
 

Accepted Solution

by:
ReeseWatt earned 0 total points
ID: 23034464
I solved this myself. It required a converter. Add a converter as a static resource and then use that converter to bring in the data. In this case, I named my photo files ItemID.jpg, so that I could bring in the appropriate by just knowing the ItemID of the current row.  Here's the applicable XAML and C# code


<UserControl.Resources>
<HMSRemnants_svcSayHello:RemnantsTest x:Key="RemnantsTestDS" d:IsDataSource="True"/>
<local:SlabID2ImageConverter x:Key="SlabID2ImageConverter"/>
</UserControl.Resources>

<StackPanel x:Name="OurStack" Orientation="Vertical">
<TextBox x:Name="InputText"/>
<TextBlock x:Name="OutputText"/>
<Button x:Name="CallServiceButton" Content="Call WCF" Click="CallServiceButton_Click"/>
<data:DataGrid x:Name="theDataGrid" AlternatingRowBackground="Beige" Grid.Row="2" Grid.Column="1" Height=" 600" Width="800" CanUserResizeColumns="True" AutoGenerateColumns="False">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="InventTypeID" Width="100" Binding="{Binding InventTypeID}" />
<data:DataGridTemplateColumn Header="ImageColumn" DisplayIndex="1" > 
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding ItemID, Converter={StaticResource SlabID2ImageConverter}}" Height="50" />
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
</data:DataGrid.Columns>
</data:DataGrid>
</StackPanel>
<?xml:namespace prefix = local />


public class SlabID2ImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Uri uri = new Uri("/Photos/" + value.ToString()+ ".jpg", UriKind.Relative);
return new BitmapImage(uri);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}





0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

580 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