我有這樣的獨立存儲功能寫入到存儲:獨立存儲不工作在Windows Phone應用程序
public static void WriteIsolatedStorage(object ObjectToStore, StorageType Key)
{
using (var storage = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
using (var storageFile = storage.CreateFile(Key.ToString()))
{
var xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(string));
switch (Key)
{
case StorageType.UserCredentials:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmWFUserCredentials));
break;
case StorageType.BackgroundAgentUserCredentials:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmWFUserCredentials));
break;
case StorageType.UserProfile:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmWFUser));
break;
case StorageType.InboxItems:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(ObservableCollection<dmWFInboxItem>));
break;
case StorageType.InboxTileItems:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(ObservableCollection<dmInboxTileInfo>));
break;
case StorageType.DocumentHeaders:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(ObservableCollection<dmWFDocumentHeader>));
break;
case StorageType.SearchCache:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(List<List<dmWFDocumentHeader>>));
break;
case StorageType.FacebookProfile:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmFBUserProfile));
break;
case
StorageType.BaseUrl:
xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmWFURLSetting));
break;
default:
break;
}
xmlSerializer.Serialize(storageFile, ObjectToStore);
}
}
然後這裏是我的功能,從這個存儲獲得:
public static dmWFURLSetting GetBaseUrl(StorageType Key)
{
try
{
using (var storage = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
{
using (var storageFile = storage.OpenFile(Key.ToString(), System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite))
{
dmWFURLSetting result = new dmWFURLSetting();
var xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(dmWFURLSetting));
return (dmWFURLSetting)xmlSerializer.Deserialize(storageFile);
}
}
}
catch (Exception)
{
return null;
}
}
很好,而且那麼這裏是我如何從m前端調用這些方法,然後viemodel,我正在使用mvvm fr這款手機應用程序。 前端電話:
public string URL = (WorkflowBase.BaseURL != null ? WorkflowBase.BaseURL.ToString() : "");
這裏是在後端的公共財產:
public static string BaseURL = AccTech.WP8.Helpers.IsolatedStorage.GetBaseUrl(Helpers.IsolatedStorage.StorageType.BaseUrl).BaseUrl.ToString();
好了,所以來這裏的怪異的一部分,我知道當我開始完全關閉獨立存儲後的仿真器(緩存)是完全乾淨的,所以如果這個函數被調用,我會得到一個空的回報......你可以看到在我的前端叫我做了一個內聯,如果,如果我得到一個空值,則使其「」。所以這裏是我運行時得到的錯誤。 PS:如果我做URL靜態應用程序的工作原理
好,這裏是錯誤我得到當我嘗試逐步完成整個過程:
我身體無力得到這個工作,我已經嘗試了谷歌提供的一切...但沒有任何反應,如果有人可以請給我一個答案,我會很高興。
,如果你需要更多的數據或信息,請讓我知道
檢查dmWFURLSetting有(德)序列化和公共構造適當的屬性。 – kindasimple 2013-04-09 20:14:58