Skip to main content

Microsoft Silverlight

ListBox.ItemsSource - Switching from large list to smaller hangs browser/silverlight.RSS Feed

(0)

UncleRedz
UncleRedz

Member

Member

8 points

7 Posts

ListBox.ItemsSource - Switching from large list to smaller hangs browser/silverlight.

Hi,

This one is a bit tricky to explain and possibly to reproduce, but basicly, take a ListBox and add a data template to it, similar to this (I used Scott's Digg data template as a starting point),

<ListBox Grid.Column="4" Grid.Row="1" x:Name="SongsListBox" SelectionChanged="SongsListBox_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>

<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions> 

<StackPanel Orientation="Vertical" Grid.Column="0" Width="40" Margin="5" Style="{StaticResource ShadedListItem}">
<TextBlock Foreground="DarkSlateGray" Style="{StaticResource ListItemBigTitle}" Text="{Binding track}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock Foreground="DarkSlateGray" Style="{StaticResource ListItemDescription}" Text="{Binding duration, Converter={StaticResource DurationConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</StackPanel>

<StackPanel Orientation="Vertical" Grid.Column="1" VerticalAlignment="Center">
<HyperlinkButton Style="{StaticResource HyperlinkTitle}" Content="{Binding title}" NavigateUri="{Binding musicFileId, Converter={StaticResource SongPlaylistConverter}}"/>
<TextBlock Style="{StaticResource ListItemDescription}" Text="{Binding artistName}" TextWrapping="Wrap"/>
</StackPanel>

</Grid>

</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

Then display this ListBox (resizing to available space) in a SL2B1 app and arrange the browser, IE7, in such a way that more than 10 but less than 11 complete items are visible.

With this setup, using code, set the ListBox.ItemsSource to a list of 15-20 items. Notice that a scroll bar is visible, don't scroll down.

Then change the ListBox.ItemsSource to a different list that contains 10 items, in other words just enough items to be visible without scrolling.

Doing this switch from the larger list to the smaller one results in something that looks like a busy loop, the CPU is maxed out and the browser stops responding. This doesn't happen all the time though, it depends on how the layout is before switching, if the browser is resized just a little, so that more or less of the list box items are visible, then this doesn't happen, so it's only when the layout is just "right".

Here's a workaround which forces the ListBox control to update it's layout before assigning the smaller list, which seems to solve the problem,

myListBox.ItemsSource = myLargeList;
...
myListBox.ItemsSource = null;
myListBox.UpdateLayout();
myListBox.ItemsSource = mySmallList;

Where as doing like this will fail, 

myListBox.ItemsSource = myLargeList;
...
myListBox.ItemsSource = mySmallList;

If source is needed or just my full XAML file, then let me know and I'll happily send it.

Cheers

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Re: ListBox.ItemsSource - Switching from large list to smaller hangs browser/silverlight.

Hello, maybe I don't understand you very well. But I can't seem to repro this issue. If you can, please share a project. Thanks.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

UncleRedz
UncleRedz

Member

Member

8 points

7 Posts

Re: ListBox.ItemsSource - Switching from large list to smaller hangs browser/silverlight.

I've sent you an email, but I could not attach anything to it using this forums email contact form.

I'll prepare a test application to make it easier to reproduce.

Cheers

masum.ahammed
masum.ah...

Member

Member

8 points

4 Posts

Re: ListBox.ItemsSource - Switching from large list to smaller hangs browser/silverlight.

 I have same problem. I developed a chat application. I used ListBox for chat window. It working fine when data size is thin. When Chat history gets increased then the chat window gets hang. Can any one have any idea.

--Masum

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities