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

2019-08-21 04:18发布

问题:

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
    }

回答1:

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.



回答2:

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.