0

在我的 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;
            }
        }
    }
4

2 回答 2

1

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

更新: 查看这篇文章,因为它解释了如何准确编写您想要完成的代码:http: //www.windowsphonegeek.com/tips/All-about-WP7-Isolated-Storage---Read-and-Save -捕获的图像

于 2012-05-25T03:32:29.323 回答
0

查看这篇文章以了解如何存储 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();
    }
}

}

于 2012-05-25T10:25:39.783 回答