Hello,
I've got a list box contain a list of cars (
lstCars).
Each car object got a list of of images (ImagesList).
I would like to fill the second ListBox (
lstCarImages) with the list images of the slected product.
I wrote the attached code (it's just a snippet) but for some reaon it's just not work.
Could someone please advice for me what I'm doing wrong or hot to do that correctly?
Please pay attention that the Car object got a property which called CarImagesList of ImagesList type and the method GetCarImages returns ImageList object.
Thanks in advance,
Lior
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
{
}
|
Dummy data
inserting:
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>
<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>
|
Raaj KumarPosted Feb 19, 2010, 2:06 AM
I have attached a code which resolves your problem. Please have a look at this and let me know if you have any problem
Regards,
Raaj
Raaj KumarPosted Feb 19, 2010, 6:27 AM
Lior KooznitsPosted Feb 19, 2010, 6:07 AM
It's working great now!
Lior KooznitsPosted Feb 19, 2010, 2:13 AM
the car list is actually a regular list contains Car object.
Each one of the object got some fields, among them is the ImagesList.
I had forgot to wirte in my last post that I succeed to bind the data to the first list box, so the problem is only with the second.
Regards,
Lior
Lalita PeddiPosted Feb 19, 2010, 12:48 AM
what is carsList object? have you set the datasource of the list box to carsList?
Best regards
Lalita