I will use CellTemplate
to do this.
Basically, you will need a collection of ImageSource
/Uri
, which will be the ItemsSource
of the DataGrid
/RadGridView
. This collection should implement INotifyCollectionChanged
and INotifyPropertyChanged
, e.g. ObservableCollection<T>
. So you code behind or view model, you could build this collection dynamically, and bind the Source
property of your Image
in Xaml.
Sample Code
Note the sample code here are for MS DataGrid
, but the Telerik RadGridView
has the similar interface, so you will be able to easily modify you code.
In Xaml, you could have something like following:
<Grid>
<Grid.Resources>
<DataTemplate x:Key="DataTemplate1">
<Image Source="{Binding}"/>
</DataTemplate>
</Grid.Resources>
<DataGrid ItemsSource="{Binding}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTemplateColumn CellTemplate="{StaticResource DataTemplate1}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
C# code will be like:
var items = new ObservableCollection<Uri>();
this.DataContext = items;
for (int i = 1; i < 4; i++)
{
items.Add(new Uri("youimage.jpg"));
}