Click here to Skip to main content
Sign Up to vote bad
good
See more: C#WPF
Hi,
I've a listbox that shows some pictures.
this is the xaml code
 <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
 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 6 Oct '12 - 2:47

Comments
Kenneth Haugland - 6 Oct '12 - 9:01
Very unusual situation consider how you populate your listbox.
Alessio Elia - 6 Oct '12 - 9:13
Is it the right way for populate the listbox?
Kenneth Haugland - 6 Oct '12 - 9:16
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:04
I've solved: When i click on Item the application call the method refreshGallery again. Sorry for my inattention :(
Jyothikarthik_N - 6 Oct '12 - 18:34
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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 586
1 Maciej Los 255
2 Slacker007 240
3 Aarti Meswania 233
4 OriginalGriff 230
0 Sergey Alexandrovich Kryukov 9,118
1 OriginalGriff 7,134
2 CPallini 3,803
3 Rohan Leuva 3,135
4 Maciej Los 2,558


Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 6 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid