How to Full Control (Read/Write) of custom resourc

2019-08-21 04:01发布

How can I read/write Keys/Values on a custom Resource File (resw) (storing string and conditional resources) ?

I added Resource File(resw) for storing settings of app. And Then ?

 private void button1_Click(object sender, RoutedEventArgs e)
    {
        ResourceContext resourceContext = ResourceContext.GetForViewIndependentUse();
        ResourceMap resourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("Resources");//resources.resw accessing in root is ok.
        var resourceValue = resourceMap.GetValue("PicPath", resourceContext);

        resourceMap.SetValue("DBPath", resourceContext,"PicPath2");//no write avaible ? ERROR LINE
    }

2条回答
劫难
2楼-- · 2019-08-21 04:24

To store read / write app values, you should use the ApplicationData API. You can have local and / or roaming settings.

Resources are read-only and are for things like UI strings, images, etc. that you load at runtime and might want to change based on things like the user's language, the accessibility settings, the display's scale factor, etc.

查看更多
Summer. ? 凉城
3楼-- · 2019-08-21 04:32

ResourceMap class does not have SetValue method. The *.resw files may contain only strings and file paths.At run time, the Windows.ApplicationModel.Resources.ResourceLoader class and the types in the Windows.ApplicationModel.Resources.Core namespace provide access to app resources, but does not provide write APIs.

查看更多
登录 后发表回答