xml序列化后,Xml文件为空

时间:2013-12-11 16:53:49

标签: c# silverlight windows-phone

我需要像<numbers>12345</numbers>这样的真实输出。但序列化后文件为空。这是我的代码:

public string Numbers { get; set; }

按钮点击事件:

private void Ref_Clicked(object sender, RoutedEventArgs e)
{   
     Item puz = new Item();
     puz.Numbers = "12345";
     Save(puz);
}

序列化功能:

public static void Save(Item settings)
{
   using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
   {
     XmlSerializer ser = new XmlSerializer(typeof(Item));
     using (IsolatedStorageFileStream isoStream = store.OpenFile(@"data.xml", System.IO.FileMode.Create))
     {
       try
       {
         ser.Serialize(isoStream, settings);
       }
       catch (Exception)
       { }
       isoStream.Close();
     }
}
}

0 个答案:

没有答案