How to Full Control (Read/Write) of custom resource resw file (Universal Windows)

眉间皱痕 提交于 2019-12-12 05:04:06

问题


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.



来源:https://stackoverflow.com/questions/47236868/how-to-full-control-read-write-of-custom-resource-resw-file-universal-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!