microsoft / microsoft/microsoft-ui-xaml

Unpackaged Win32 app using WinUI3 Xaml Island - problems with external fonts referenced in xaml

Open
#10,054 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area-Islands area-Resources bug team-Core
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

`` does not work.

It is probably a very old problem that no one tried to fix or find a workaround. It was [reported](https://github.com/microsoft/microsoft-ui-xaml/issues/3766) almost five years ago...

WinUI3 Xaml does not support `file:` as part of `Uri`. It can be seen in `ResourceManager::TryGetLocalResource` where only `ms-appdata:`, `ms-appx:` and `ms-resource:` are handled.

That is understandable for UWP applicarions and Packaged Desktop applications (although when they have `broadFileSystemAccess` it should work too, right?). But it should work for Unpackaged Deskop application.

While searching for workaround I found that

- `ms-appdata:` cannot be used because it requires packaged application.
- `ms-appx:` and `ms-resource:` can be used in unpackaged application to reach files in exe directory (and its subdirectories)

`ms-appx:///xxx` is essentialy transformed to `ms-resource:///files/xxx`.
`ms-resource:///files/xxx` uses `m_pFallbackResourceProvider` and combines `xxx `with `m_pBaseUri`. `m_pBaseUri` is initialized to `GetModuleFileName(NULL, applicationDirectory, MAX_PATH)` in `CommonResourceProvider::Create`.

This workaround looks like implementation detail and might stop working in future. And of course is limited to exe directory only. What else should we use?

### Steps to reproduce the bug

`` does not work.

### Expected behavior

`` Should work.

### Screenshots

_No response_

### NuGet package version

WinUI 3 - Windows App SDK 1.6.1: 1.6.240923002

### Windows version

Windows 11 (22H2): Build 22621

### Additional context

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading ResourceManager::TryGetLocalResource and CommonResourceProvider::Create, focusing on how file:, ms-appdata:, ms-appx:, and ms-resource: URIs are handled. Reproduce the external-font case in an unpackaged Win32 Xaml Island application and determine how the resource provider should resolve a font outside the executable directory. Done means the file:///c:/font.ttf#font reference works as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.