Reputation: 753
I have a ListBox with around 50 entries. Every entry has 3 pictures and a text
It looks something like this
<grid>
<TextBlock x:Name="textBlock" Text="{Binding Title}" Foreground="{Binding Brush}" Grid.Column="1" Margin="8,43,-256,8" FontSize="26.667" FontFamily="Segoe WP" TextWrapping="Wrap" RenderTransformOrigin="0.5,0.5" TextTrimming="WordEllipsis" Width="248" Height="90" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Image x:Name="image2" Source="{Binding Picture3}" Margin="48,8,29,33" RenderTransformOrigin="0.5,0.5" Width="100" Height="100" VerticalAlignment="Center" HorizontalAlignment="Center" />
<Image x:Name="image" Source="{Binding Picture2}" Margin="58,16,18,24" RenderTransformOrigin="0.5,0.5" Width="100" Height="100" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Image x:Name="image1" Source="{Binding Picture1}" Margin="69,25,8,16" RenderTransformOrigin="0.5,0.5" Width="100" Height="100" HorizontalAlignment="Center" VerticalAlignment="Center" />
</grid>
The problem is that if I start the application and scroll to the end, it takes about 5-10 seconds to show the enries. Even worse is, that if I scroll up again, the same happens. This behavior gets worse if I download files in a BackgroundWorker Thread which causes the UI to sometimes freeze for seconds.
How can a BackgroundWorker Thread affekt the UI ? And is there something I should in particular take care when using a listbox ?
EDIT:
The Picture property is kind of a hack to create a working DataBinding for the pictures
private BitmapImage m_mediumCoverArt = null;
public BitmapImage MediumCoverWithoutDownload
{
get
{
if (m_mediumCoverArt == null)
{
try
{
using (IsolatedStorageFile isoStore =
IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isoStore.FileExists(GlobalVariables.BEAT_COVER_FOLDER + "/" + GetPath.ForCoverArt(this.m_pictureURL + GlobalVariables.MEDIUM_IMAGE_POSTFIX)))
return null;
using (IsolatedStorageFileStream isoStream =
new IsolatedStorageFileStream(GlobalVariables.BEAT_COVER_FOLDER + "/" + GetPath.ForCoverArt(this.m_pictureURL + GlobalVariables.MEDIUM_IMAGE_POSTFIX),
FileMode.Open, isoStore))
{
m_mediumCoverArt = new BitmapImage();
m_mediumCoverArt.SetSource(isoStream);
return m_mediumCoverArt;
}
}
}
catch (Exception)
{
return null;
}
}
else
{
return m_mediumCoverArt;
}
}
}
I know that the loading of the pictures runs in the UI Thread, but it takes only milliseconds and it happens only one time as well. So even while this could explain the long first loading period, it should work later on without a problem.
Upvotes: 0
Views: 240
Reputation: 8126
What is a Picture*
property? It's a Url to external resource? By default image decoding performs on UI thread.
Learn more about image creation options at Off-thread decoding of images on Mango . Maybe it helps for you.
Upvotes: 1