Skip to content

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

@benstevens48

Description

@benstevens48

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions