• WP7备注(13)(独立储存)


    IsolatedStorageSettings:

    public Brush BackgroundBrush { set; get; }

    void LoadSettings()
    {
    IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
    Color clr;
    if (settings.TryGetValue<Color>("backgroundColor", out clr))
    BackgroundBrush = new SolidColorBrush(clr);
    }
    void SaveSettings()
    {
    IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
    if (BackgroundBrush is SolidColorBrush)
    {
    settings["backgroundColor"] = (BackgroundBrush as SolidColorBrush).Color;
    settings.Save();
    }
    }

    XNA独立储存:

    public class Settings
    {
    const string filename = "settings.xml";
    // Application settings
    public Color BackgroundColor { set; get; }
    public Settings()
    {
    BackgroundColor = Color.Navy;
    }
    public void Save()
    {
    IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
    IsolatedStorageFileStream stream = storage.CreateFile(filename);
    XmlSerializer xml = new XmlSerializer(GetType());
    xml.Serialize(stream, this);
    stream.Close();
    stream.Dispose();
    }
    public static Settings Load()
    {
    IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
    Settings settings;
    if (storage.FileExists(filename))
    {
    IsolatedStorageFileStream stream =
    storage.OpenFile("settings.xml", FileMode.Open);
    XmlSerializer xml = new XmlSerializer(typeof(Settings));
    settings = xml.Deserialize(stream) as Settings;
    stream.Close();
    stream.Dispose();
    }
    else
    {
    settings = new Settings();
    }
    return settings;
    }
    }
    PhoneApplicationService appService = PhoneApplicationService.Current;
    appService.Launching += OnAppServiceLaunching;
    appService.Activated += OnAppServiceActivated;
    appService.Deactivated += OnAppServiceDeactivated;
    appService.Closing += OnAppServiceClosing;
    
    void OnAppServiceLaunching(object sender, LaunchingEventArgs args)
    {
    settings = Settings.Load();
    }
    void OnAppServiceActivated(object sender, ActivatedEventArgs args)
    {
    settings = Settings.Load();
    }
    void OnAppServiceDeactivated(object sender, DeactivatedEventArgs args)
    {
    settings.Save();
    }
    void OnAppServiceClosing(object sender, ClosingEventArgs args)
    {
    settings.Save();
    }
  • 相关阅读:
    手机网页版知乎内容隐藏效果的实现
    Egret白鹭开发微信小游戏手机震动功能
    Egret白鹭开发微信小游戏分享功能
    Egret白鹭开发微信小游戏(使用皮肤搭建UI,代码调用组件功能)
    Egret白鹭开发微信小游戏程序跳转功能(由一个小游戏跳转到另一个小游戏)
    Egret白鹭开发小游戏之自定义load加载界面
    unity shader 纹理&透明效果
    unity shader 入门
    unity shader之预备知识
    Unity官方案例精讲_2015_优化
  • 原文地址:https://www.cnblogs.com/otomii/p/2030423.html
Copyright © 2020-2023  润新知