Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I've a listbox that shows some pictures.
this is the xaml code
XML
<ListBox Height="500" Name="lbThumbnails" IsEnabled="False" SelectionMode="Single" ItemsSource="{Binding Source}" >
                           <ListBox.ItemsPanel>
                               <ItemsPanelTemplate>
                                   <StackPanel></StackPanel>
                               </ItemsPanelTemplate>
                           </ListBox.ItemsPanel>
                           <ListBox.ItemTemplate>

                               <DataTemplate>
                                   <Border BorderBrush="#FFB4B4B4" Opacity="0.7" BorderThickness="2" CornerRadius="5" >
                                       <Image Source="{Binding UriSource}"  Stretch="Fill" Width="100" Height="100" Margin="20"  />
                                   </Border>
                               </DataTemplate>
                           </ListBox.ItemTemplate>
                       </ListBox>


this is the code-behind
C#
pictures = new List<BitmapImage>();
           try
           {
               DirectoryInfo pictureImageDir = new DirectoryInfo("Thumbnails");
               foreach (FileInfo koiImageFile in pictureImageDir.GetFiles("*.jpg"))
               {
                   Uri uri = new Uri(koiImageFile.FullName);
                   pictures.Add(new BitmapImage(uri));
               }
               lbThumbnails.ItemsSource = pictures;
           }
           catch (Exception ex)
           {
               System.Windows.MessageBox.Show("Errore non previsto");
           }

The loading works but after the user click on an item, all the items disappears.
This is the first time that I see this kind of error and i've no idea of what is the problem.
PS: I've tried to manage the selection changed event of listbox, but the execution flow doesn't enter in that code. It's very strange.
Can you help me?

Greats
Posted
Comments
Kenneth Haugland 6-Oct-12 9:01am    
Very unusual situation consider how you populate your listbox.
Alessio Elia 6-Oct-12 9:13am    
Is it the right way for populate the listbox?
Kenneth Haugland 6-Oct-12 9:16am    
I won't have done it that way:
http://msdn.microsoft.com/en-us/library/system.windows.controls.listview(v=vs.85).aspx
Alessio Elia 6-Oct-12 10:04am    
I've solved:
When i click on Item the application call the method refreshGallery again.
Sorry for my inattention :(
[no name] 6-Oct-12 18:34pm    
Alessio, If the question is resolved - provide the solution under "I've solved it myself" and close it, so it doesn't hang around in the unanswered lot. Thnx!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900