Skip to content

Remove assumptions that XamlRoot::Content() matches Window size #10211

Open

Description

Problem Description

There are at least two callsites that assume that the XamlRoot Size or the ActualSize of the XamlRoot::Content matches the size of the XAML Islands HWND:

  • if (Is19H1OrHigher()) {
    // XamlRoot added in 19H1 - is required to be set for XamlIsland scenarios
    if (auto xamlRoot = React::XamlUIService::GetXamlRoot(m_context.Properties().Handle())) {
    m_popup.XamlRoot(xamlRoot);
    root = xamlRoot.Content().as<xaml::FrameworkElement>();
    }
    }
  • auto rootChangedToken = xamlRoot.Changed([=](auto &&, auto &&) {
    const auto rootSize = xamlRoot.Size();
    const auto popupRoot = xaml::Media::VisualTreeHelper::GetParent(dialog);
    const auto nChildren = xaml::Media::VisualTreeHelper::GetChildrenCount(popupRoot);
    if (nChildren == 2) {
    // The first is supposed to be the smoke screen (Rectangle), and the second the content dialog
    if (const auto smoke =
    xaml::Media::VisualTreeHelper::GetChild(popupRoot, 0).try_as<xaml::Shapes::Rectangle>()) {
    const auto assertDialog =
    xaml::Media::VisualTreeHelper::GetChild(popupRoot, 1).try_as<xaml::Controls::ContentDialog>();
    if (assertDialog == dialog) {
    smoke.Width(rootSize.Width);
    smoke.Height(rootSize.Height);
    dialog.Width(rootSize.Width);
    dialog.Height(rootSize.Height);
    }
    }
    }
    });

While this is generally a good assumption, this may not always be the case. For example, in our app, we've worked around a XAML Islands bug microsoft/microsoft-ui-xaml#2101 by making the root Grid larger than the HWND by a factor equivalent to the DPI scale factor.

Steps To Reproduce

There's no immediate repro in this repo, but one way to repro is to try and build a drag and drop handler for a XAML Islands react-native-windows app, and see that the full window is not a valid drop target for high DPI scale settings.

Expected Results

React Native Windows may want to assume that the root level content or XamlRoot matches the HWND size by default, but we should allow apps to override this behavior with a "window sizing root" target element that does match the window size.

CLI version

npx react-native --version

Environment

npx react-native info

Target Platform Version

No response

Target Device(s)

No response

Visual Studio Version

No response

Build Configuration

No response

Snack, code example, screenshot, or link to a repository

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions