简体   繁体   English

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

[英]How to use resource qualifier names in UWP AppData folder

For my UWP app, I'm trying to move some assets to my AppData folder.对于我的 UWP 应用程序,我正在尝试将一些资产移动到我的 AppData 文件夹中。 I'm surprised that I've seemed to lose the option of using qualifier names in the process.我很惊讶我似乎失去了在这个过程中使用限定符名称的选项。

For example, for the following pair of images例如,对于下面的一对图像

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

I used to have the following image source:我曾经有以下图像来源:

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

After moving the images to the AppData folder, I'm only seeing the image if I'm explicit about which image I use, like this:将图像移动到 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>

Then, in order to select the appropriate image, I would have to subscribe to the the QualifierValues.MapChanged event as shown in this answer, and set up my own logic to get the appropriate ImageSource.然后,为了 select 获得适当的图像,我必须订阅 QualifierValues.MapChanged 事件, 如此答案所示,并设置我自己的逻辑以获取适当的 ImageSource。

I've been looking here and here for some more information, but I cannot see anything that mentions how to use qualifier names in the AppData folder.我一直在此处此处查看更多信息,但我看不到任何提及如何在 AppData 文件夹中使用限定符名称的内容。

How to use resource qualifier names in UWP AppData folder如何在 UWP AppData 文件夹中使用资源限定符名称

I have to say you can't use resource qualifier names in UWP AppData folder, the app will not preload resource where in the AppData folder.我不得不说你不能在 UWP AppData文件夹中使用资源限定符名称,应用程序不会预加载AppData文件夹中的资源。 so it will not work for setting image source with simple file name.因此它不适用于使用简单文件名设置图像源。

If you do want to use resource qualifier names in UWP AppData folder.如果您确实想在 UWP AppData 文件夹中使用资源限定符名称。 we have a workaround that use IValueConverter to return matched filename base on current scale.我们有一个解决方法,使用IValueConverter返回基于当前比例的匹配文件名。 for getting current scale please refer to ResourceContext document.要获取当前比例,请参阅ResourceContext文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM