如何在 UWP AppData 文件夹中使用资源限定符名称

How to use resource qualifier names in UWP AppData folder

对于我的 UWP 应用,我正在尝试将一些资产移动到我的 AppData 文件夹中。我很惊讶我似乎失去了在这个过程中使用限定符名称的选项。

例如,对于下面这对图像

Assets/Header/header.scale-100.jpg
Assets/Header/header.scale-200.jpg

我以前有以下图片来源:

<ImageSource x:Key="Header">/Assets/Header/header.jpg</ImageSource>
        

将图像移动到 AppData 文件夹后,如果我明确说明我使用的图像,我只会看到图像,如下所示:

<ImageSource x:Key="Header100">ms-appdata:///local/Assets/Header/header.scale-100.jpg</ImageSource>
<ImageSource x:Key="Header200">ms-appdata:///local/Assets/Header/header.scale-200.jpg</ImageSource>

然后,为了 select 合适的图像,我必须订阅 QualifierValues.MapChanged 事件,如 this 答案所示,并设置我自己的逻辑以获取合适的 ImageSource。

我一直在寻找 here and here 的更多信息,但我没有看到任何提及如何在 AppData 文件夹中使用限定符名称的内容。

How to use resource qualifier names in UWP AppData folder

我不得不说你不能在 UWP AppData 文件夹中使用资源限定符名称,应用程序不会预加载 AppData 文件夹中的资源。所以它不适用于设置简单文件名的图像源。

如果您确实想在 UWP AppData 文件夹中使用资源限定符名称。我们有一个使用 IValueConverter to return matched filename base on current scale. for getting current scale please refer to ResourceContext 文档的解决方法。