在 Windows 8 中序列化 XML 数据(增量存储) [英] Serialize XML data (Incremental storing) in Windows 8

查看:21
本文介绍了在 Windows 8 中序列化 XML 数据(增量存储)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Windows8 中序列化 XMl 数据.对于 Metro,方法是异步的.为了保存,可以传递一个动作,一旦保存操作完成,该动作将被调用.加载数据时,您需要传递一个接收加载数据的操作和一个异常参数,如果无法加载数据,将填充该参数.怎么可能.

How to serialize XMl data in Windows8.For Metro the methos are asynchronous. For saving an action can be passed that will be called once the save operation is complete. When loading data you'll want to pass an action that will received the loaded data and an exception parameter that will be populated if the data could not be loaded. How is it possible.

下面是wp7中序列化的代码..在 Windows 8 中怎么可能??

Below is the code for serializing in wp7.. how is it poessible in windows 8??

private void SaveProfileData(Profiles profileData)
    {
        XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
        xmlWriterSettings.Indent = true; 
        ProfileList = ReadProfileList();
        using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
        {
            using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("profile.xml", FileMode.Create))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(List<Profiles>));
                using (XmlWriter xmlWriter = XmlWriter.Create(stream, xmlWriterSettings))
                {
                    serializer.Serialize(xmlWriter, GenerateProfileData(profileData));
                }
            }
        }
    }

推荐答案

我构建了一个数独应用程序,但遇到了同样的问题.我尝试在 Visual Studio 2012 中将代码从 wp7 更改为 win 8,但我的应用程序尚未运行.也许我的代码可以帮助你.

I build a Sudoku app and i have the same problem. I try to Change the code from wp7 to win 8 in visual studio 2012 but my app didn't work yet. Perhaps my code can be help you.

public void SaveToDisk()
        {           
             if (Windows.Storage.ApplicationData.Current.LocalSettings.Values.ContainsKey(key))
                {
                    if (Windows.Storage.ApplicationData.Current.LocalSettings.Values[key].ToString() != null)
                    { 
                        //do update
                        Windows.Storage.ApplicationData.Current.LocalSettings.Values[key] = value;
                    }
                }
             else 
                {   // do create key and save value, first time only.

                    Windows.Storage.ApplicationData.Current.LocalSettings.CreateContainer(key, ApplicationDataCreateDisposition.Always);
                    if (Windows.Storage.ApplicationData.Current.LocalSettings.Values[key] == null)
                    {
                        Windows.Storage.ApplicationData.Current.LocalSettings.Values[key] = value;
                    }

                 using (StreamWriter writer = new StreamWriter(stream))
                    {
                        List<SquareViewModel> s = new List<SquareViewModel>();
                        foreach (SquareViewModel item in GameArray)
                            s.Add(item);

                        XmlSerializer serializer = new XmlSerializer(s.GetType());
                        serializer.Serialize(writer, s);
                    }
                 }                

        }

这篇关于在 Windows 8 中序列化 XML 数据(增量存储)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆