2012-02-13 61 views
1

我正在編寫一個由透視控件組成的Windows Phone應用程序,並且我想在不同的透視項目之間切換時更改背景。根據當前數據透視項目的視圖模型信息,我將加載一個與其匹配的背景。Windows Phone背景圖像更改性能問題

我在做什麼現在是我有一些代碼在onSelectionChanged處理我的轉動控制的:

 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; 

這做我想要什麼,但表現糟糕,當我不同的支點項目之間切換,它將暫停大約半秒來加載圖像。

任何有關我應該如何解決性能問題的建議?

謝謝!

回答

4

我不驚訝這會導致性能問題,每次更改背景時手機都必須解碼全屏圖像。我會建議讓你的透視控制透明,然後有一個'堆棧'的圖像。然後,您可以更改其可見性以顯示/隱藏每個可見性。例如:

<Grid> 
    <Image Source="backgroundOne.jpg" Visibility="Visible"/> 
    <Image Source="backgroundTwo.jpg" Visibility="Collapsed"/> 

    <Pivot> 
    ... 
    </Pivot> 
</Grid> 
+0

這很好,謝謝! – 2012-02-13 21:08:53