Reputation: 3111
I'm writing a windows phone app that consist of a pivot control, and I want to change the background as I switch between different pivot items. Based on current pivot item's view model information, I will load a background that matches it.
Now what I'm doing is I have some code in onSelectionChanged
handler of my pivot control:
if (currentCondition.Contains("a"))
{
image = new BitmapImage(new Uri("Images/a.jpg", UriKind.Relative));
}
else if (currentCondition.Contains("b"))
{
image = new BitmapImage(new Uri("Images/b", UriKind.Relative));
}
ImageBrush ib = new ImageBrush();
ib.ImageSource = image;
this.PivotControl.Background = ib;
This did what I want but the performance is bad, when I switch between different pivot items, it will pause for about half a second to load the image.
Any suggestion on how should I approach to solve the performance problem?
Thanks!
Upvotes: 1
Views: 377
Reputation: 70160
I am not surprised that this causes performance issues, the phone has to decode a full-screen image each time you change the background. I would suggest making your pivot control transparent, then have a 'stack' of images behind. You can then change their visibility in order to show / hide each one. For example:
<Grid>
<Image Source="backgroundOne.jpg" Visibility="Visible"/>
<Image Source="backgroundTwo.jpg" Visibility="Collapsed"/>
<Pivot>
...
</Pivot>
</Grid>
Upvotes: 4