views:

368

answers:

1

I have a WPF ListBox that displays images loaded from a local folder, usually somewhere between 1- 300). I'm using a converter in my imageTemplate to make sure and show thumbnails of the images, and not the images in their full size. Even while doing this, it still can take several seconds to load initially. My question is, how do I know in my ListBox when the loading of ListBoxItems Begins/Ends, so that I can set the Mouse Cursor to a waiting status? I'm looking for a way to notify that user that something is happening..

Here is what my ListBox looks like in XAML:

<ListBox SelectionMode="Extended"
         ItemsSource="{Binding Path=ImageFiles}"
         ItemTemplate="{StaticResource imageTemplate}"
         ScrollViewer.CanContentScroll="True"
         ScrollViewer.HorizontalScrollBarVisibility="Disabled"
         ScrollViewer.IsDeferredScrollingEnabled="False"
         VirtualizingStackPanel.VirtualizationMode="Recycling"
         x:Name="images">
        <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                 <WrapPanel />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
   </ListBox>

Thanks!

A: 

I answered a similar question, here.

If you don't want to do a pop-up, you could also do something similar by attaching a translucent rectangle (or some other filling control), with a message/animation in front of it, to the listbox or its parent control that gets closed asynchronously like the popup in the linked answer does. I did something like that for Silverlight back before the BusyIndicator was available, and it worked quite well. I set it up as a user control with a property for the control it should cover, so it was easily re-used.

Mike Pateras
Hi Mike,I looked at your answer to a similar question. My problem is since the ListBox is using Data Binding to get the items, I"m not sure how to tell when it is loading. I'm not overly concerned about what to show while it's loading, but rather being able to determine when the loading starts and ends. Any ideas? Thanks, Rob
Taylor
Sorry, I see now where I missed your specific question. Can you determine what exactly is taking the time? Assuming it's not the binding itself, it's probably the reading of the images from the disk. Or perhaps it's the thumbnail conversion process (ifyou're doing that at load time). Either way, you could build your collection of images before doing the bind, and then throw an event when that's done. That should be doable. Is that clear?
Mike Pateras
I think you are right that most of the time is spent reading images from disk, with a little time doing the conversions (everything is being done through the Binding directly to an XML file). That might be what I have do, build the collection before doing the bind... I'll see if I can work that in. Thanks!
Taylor