2012-05-25 53 views
0

在我的Windows Phone 7应用程序中,我创建了一个按钮来更改默认背景图像,用户可以在应用程序上拥有自己的自定义皮肤。它工作完美。但是,当用户退出应用程序并重新启动应用程序时,应用程序的背景图像将更改为默认值。但我需要的是,应用程序应该有用户选择的最后一个图像,即使启动不了。的时代。谁能帮我这个?预先感谢您的辛勤工作!背景图像更改为默认的WP7

private void BackgroundBrowserIcon_MouseEnter(object sender, MouseEventArgs e) 
    { 
     var PhotoChooser = new PhotoChooserTask(); 
     PhotoChooser.Completed += new EventHandler<PhotoResult>(PhotoChooser_Completed); 
     PhotoChooser.Show(); 
    } 

    void PhotoChooser_Completed(object sender, PhotoResult e) 
    { 
     { 
      if (e.TaskResult == TaskResult.OK) 
      { 
       System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage(); 
       bmp.SetSource(e.ChosenPhoto); 
       var app = Application.Current as App; 

       if (app == null) 
        return; 
       var imageBrush = new ImageBrush { ImageSource = bmp, Opacity = 1.0d }; 
       this.LayoutRoot.Background = imageBrush; 
       app.backchanged = true; 
       app.appbrush = imageBrush; 
      } 
     } 
    } 

回答

1

您是否使用IsolatedStorageSettings存储上次选择的照片,然后将其加载到应用程序启动?

更新: 退房这篇文章,因为它解释如何编写你希望完成什么:http://www.windowsphonegeek.com/tips/All-about-WP7-Isolated-Storage---Read-and-Save-Captured-Image

+0

不,我不知道如何使用IsolatedStorageSettings,我不知道该怎么办,到存储最后选择的照片。请在这件事上给予我帮助! –

+0

查看我在回答中发布的链接。这应该指向正确的方向。 :) –

0

看看这个article学习如何储存IsolatedStorageSettings。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using Microsoft.Phone.Controls; 
using System.IO.IsolatedStorage; 


namespace F5debugWp7IsolatedStorage 
{ 
    public partial class MainPage : PhoneApplicationPage 
    { 
    // Constructor 
    public MainPage() 
    { 
     InitializeComponent(); 
    } 

    private void button3_Click(object sender, RoutedEventArgs e) 
    { 
     IsolatedStorageSettings ISSetting = IsolatedStorageSettings.ApplicationSettings; 

     if (!ISSetting.Contains("DataKey")) 
     { 
      ISSetting.Add("DataKey", txtSaveData.Text); 
     } 
     else 
     { 
      ISSetting["DataKey"] = txtSaveData.Text; 
     } 
     ISSetting.Save(); 
    } 
} 

}

+0

如何使用上面的代码的图像? –

+0

你有图像,所以你可以重新绑定到背景?你能保存图像的位置吗? –

+0

其实默认情况下,我有地方有6个图像,用户也可以选择自己的照片(从照片选择器任务)。所以我需要的是,如果用户更改背景图片,我需要我的应用程序记住该应用程序下次启动时的背景图片。 –