在wp7上,背景图像更改为默认值

时间:2012-05-25 02:50:15

标签: c# windows-phone-7

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

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;
            }
        }
    }

2 个答案:

答案 0 :(得分:1)

您是否使用IsolatedStorageSettings存储上次选择的照片,然后在应用启动时加载它?

<强>更新 看看这篇文章,因为它解释了如何准确编码你想要完成的任务:http://www.windowsphonegeek.com/tips/All-about-WP7-Isolated-Storage---Read-and-Save-Captured-Image

答案 1 :(得分: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();
    }
}

}