Touble binding ListBox to source item selected from another listBox

Feb 18 2010 5:12 PM

 

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<MyImage>
    {
    }
 
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>

                            <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>

Answers (5)