Search code examples
c#uwpappdata

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. 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:

<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.

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.


Solution

  • How to use resource qualifier names in UWP AppData folder

    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. 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. we have a workaround that use IValueConverter to return matched filename base on current scale. for getting current scale please refer to ResourceContext document.