0

如何在自定义资源文件 (resw) 上读取/写入键/值(存储字符串和条件资源)?

我添加了用于存储应用程序设置的资源文件(resw)。接着 ?

 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
    }
4

2 回答 2

1

ResourceMap 类没有SetValue方法。*.resw 文件可能仅包含字符串和文件路径。在运行时,Windows.ApplicationModel.Resources.ResourceLoader 类和 Windows.ApplicationModel.Resources.Core 命名空间中的类型提供对应用资源的访问,但不提供写入蜜蜂。

于 2017-11-14T02:18:18.600 回答
1

要存储读/写应用程序值,您应该使用ApplicationDataAPI。您可以进行本地和/或漫游设置。

资源是只读的,用于您在运行时加载的 UI 字符串、图像等内容,并且可能希望根据用户语言、可访问性设置、显示比例因子等内容进行更改。

于 2017-11-14T02:51:11.707 回答