microsoft / microsoft/WindowsAppSDK

Suggestion: XamlRoot should be available immediately as a property of the Window class

Open
#6,354 0 comments 0 reactions 0 assignees View on GitHub
area-Windowing needs-triage
Dominant language
C++
Stars
4.7k
Forks
471
Avg merge
3d 13h
Merged PRs (30d)
28

Description

I would find it very convenient to be able to get the associated XamlRoot immediately after creating a Window. In particular I want the rasterization scale and also the display id (via ContentIslandEnvironment). I can use Win32 interop to get these but that is inconvenient from a C# app. I can also wait for the XamlRoot to be created, but then it gets messy with a potential unnecessary rasterization scale change (have to assume 1 to start with) and waiting for events to fire (see next paragraph).

At the very least, it would be good to document a guarantee of when the XamlRoot will be created. If I add a UIElement as Content to the Window, is it guaranteed to be available on the UIElement after the UIElement's Loaded event is fired, and will that happen even before Window.Activate is called? It seems so at the moment but I don't want to rely on that behavior if it's an implementation detail. Further, it would also be nice to document whether the XamlRoot on an element will ever be set back to null (for example on Unloaded - it seems not currently, which is good), and whether the XamlRoot could ever change (e.g. removing from one visual tree and adding to the visual tree of another window - I haven't tried this), and if so maybe consider an event in case this happens (or perhaps it will always coincide with Unloaded/Loaded?).

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the Window and XamlRoot API entry points, then trace UIElement.Loaded and Window.Activate behavior around ContentIslandEnvironment. Check the timing, lifetime, and reassignment behavior of XamlRoot when elements move between visual trees. Done means the requested immediate access or explicit guarantees cover rasterization scale, display id, creation timing, and possible changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, csharp
Domain
api, desktop
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.