The classes: public class MyImage { BitmapImage image; public MyImage(BitmapImage bitImage) { image = bitImage; } public BitmapImage Image { get { return image; } set {value = Image; } } } public class ImagesList : ObservableCollection<MyImage> { }
public class MyImage
{ BitmapImage image;
public MyImage(BitmapImage bitImage)
{
image = bitImage;
}
public BitmapImage Image
get { return image; } set {value = Image; }
} public class ImagesList : ObservableCollection<MyImage>
{ }
Dummy data
Car car1 = new Car();
car1.licenceNumber = "1853535";
car1.CarImagesList = GetCarImages(car1.licenceNumber); // This method return list of the MyImage object
Car car2 = new Car();
car2.licenceNumber = "1223920";
car2 .CarImagesList = GetCarImages(car2 .licenceNumber);
carsList.Add(car1);
carsList.Add(car2);
The xaml: <ListBox Name="lstCars" HorizontalContentAlignment="Stretch" HorizontalAlignment="Left" IsSynchronizedWithCurrentItem="True"> <ListBox.ItemTemplate> <DataTemplate> <Border Margin="5"> <Grid Margin="3"> <Grid.RowDefinitions> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <TextBlock Grid.Row="0" Text="{Binding Path=Producer}"></TextBlock> <TextBlock Grid.Row="1" Text="{Binding Path=Model}"></TextBlock> <TextBlock Grid.Row="2" Text="{Binding Path=LicenceNumber}"></TextBlock> </Grid> </Border> </DataTemplate> </ListBox.ItemTemplate> </ListBox> <ListBox Name="lstCarImages" HorizontalContentAlignment="Stretch" ItemsSource="{Binding Path=CarImagesList}" IsSynchronizedWithCurrentItem="True"> <ListBox.ItemTemplate> <DataTemplate> <Border Margin="5"> <Image Source="{Binding Path=Image}"></Image> </Border> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
<ListBox Name="lstCars" HorizontalContentAlignment="Stretch" HorizontalAlignment="Left" IsSynchronizedWithCurrentItem="True">
<ListBox.ItemTemplate>
<DataTemplate>
<Border Margin="5">
<Grid Margin="3">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding Path=Producer}"></TextBlock>
<TextBlock Grid.Row="1" Text="{Binding Path=Model}"></TextBlock>
<TextBlock Grid.Row="2" Text="{Binding Path=LicenceNumber}"></TextBlock>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox Name="lstCarImages" HorizontalContentAlignment="Stretch" ItemsSource="{Binding Path=CarImagesList}" IsSynchronizedWithCurrentItem="True">
<Image Source="{Binding Path=Image}"></Image>