Silverlight MVVM 隔離存儲 (Silverlight MVVM Isolated Storage)


問題描述

Silverlight MVVM 隔離存儲 (Silverlight MVVM Isolated Storage)

I've tried to use IsolatedStorageSettings in my ViewModel, but these are not getting retained across browser refreshes (F5).

for example;

//look in the IsoStore for remembered details


    IsRememberMe = IsolatedStorageSettings.ApplicationSettings.Contains(Constants.LOGIN_REMEMBERED_USERNAME);

        if (IsRememberMe)
        {
            UserName = IsolatedStorageSettings.ApplicationSettings[Constants.LOGIN_REMEMBERED_USERNAME] as string;
        }

Do I need to do something differently in my MVVM ViewModel's??

EDIT It's worth noting that this code is sitting in a referenced project - so ultimately a seperate XAP file to the parent XAP that is loaded in the browser - might this cause the settings to be lost on each refresh?

THanks, Mark


參考解法

方法 1:

Well...

In my case I have issues using Application Isolated Storage, each time I deployed a new version of my app (just for instance changing the color of a button I lost my Iso Storage :-().

I move to use SiteStorage instead of Application level, and it worked:

http://www.tipsdotnet.com/TechBlog.aspx?PageIndex=0&BLID=13

On the other hand what I had done with Iso Storage is perform CRUD on folders and files, not sure abou that other kind of settings.

HTH      Braulio

方法 2:

I would think one of two things is happening here.  Either your binding isn't working correctly in both directions so either the persistence or the retrieval code is never hit.  Or, you're storing these values in application level iso storage from two different applications (or something to that effect).  Make sure your code is being hit in both cases (storing and retrieving) and make sure you're accessing the iso store from the same place (if you're using application level isolation, store/retrieve from the same application, etc).

(by Mark CooperBraulioRich)

參考文件

  1. Silverlight MVVM Isolated Storage (CC BY-SA 3.0/4.0)

#mvvm #isolatedstorage #silverlight






相關問題

WPF View 在關閉時將 ViewModel 屬性設置為 null (WPF View sets ViewModel properties to null on closing)

在文本框中正確輸入後啟用按鈕 (Button Enable After Correct Input In TextBox)

WPF說數據項不為空時為空 (WPF says that data item is null when it is not null)

MVVM - 如何將 ViewModel 包裝在 ViewModel 中? (MVVM - How to wrap ViewModel in a ViewModel?)

關於服務參考和 MVVM 模式的幾個一般問題 (A few general questions about Service Reference and MVVM pattern)

WPF MVVM 鏈接視圖 (WPF MVVM Linked Views)

wpf 樹視圖 mvvm (wpf treeview mvvm)

如何在 MVVM Light 的 ListView 中的 ComboBox 中顯示列表? (How to show a List in a ComboBox in a ListView in MVVM Light?)

多次調用 PropertyChanged 的 ViewModel 屬性 (ViewModel properties with multiple calls to PropertyChanged)

如何將圖像存儲在類庫中並從任何類訪問它 (How can i store an image in a class library and access it from any class)

Silverlight MVVM 隔離存儲 (Silverlight MVVM Isolated Storage)

如何將文本框的borderBrush屬性綁定到viewmodel中的屬性,類型轉換錯誤 (How to bind the borderBrush property of a textbox to a property in viewmodel, type conversion error)







留言討論