2012-08-09 65 views
0

我添加了一個按鈕(BackgroundBrowser),以隨機更改我的應用程序的背景。但是,當我退出並重新啓動應用程序時,用戶設置的最後一張圖像與當前背景圖像不同。我不知道如何檢索在我的應用程序中設置的最後一張圖像,並將其作爲當前背景圖像。以下是我用來隨機更改背景的代碼。在啓動時檢索wp7上的自定義背景圖像

private void BackgroundBrowser_Click(object sender, RoutedEventArgs e) 
    { 
     string imguri = ""; 

     click_count = click_count % 5; 
     switch (click_count) 
     { 
      case 0: imguri = "Image/bg.jpg"; break; 
      case 1: imguri = "Image/bg1.jpg"; break; 
      case 2: imguri = "Image/bg3.jpg"; break; 
      case 3: imguri = "Image/bg2.jpg"; break; 
      case 4: imguri = ""; break; 
     } 
     click_count++; 

     var app = Application.Current as App; 
     app.appBmp = new BitmapImage(new Uri(imguri, UriKind.Relative)); 
     ImageBrush imageBrush = new ImageBrush(); 
     imageBrush.Stretch = Stretch.UniformToFill; 
     imageBrush.Opacity = 0.7; 
     imageBrush.ImageSource = app.appBmp; 
     this.LayoutRoot.Background = imageBrush; 
     app.appbrush = imageBrush; 
     app.backchanged = true; 
    } 

有人可以幫忙嗎?謝謝你的幫助!

回答

0

只需將其保存在隔離存儲器中即可。例如,保存uri字符串(「Images/bg.jpg」),然後在重新啓動應用程序時,檢查IsolatedStorage中是否存在值,然後讀取它,然後相應地設置背景。

Isolated Storage