Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FindName() does not work in WinUI3 #9842

Open
HO-COOH opened this issue Jul 22, 2024 · 2 comments
Open

FindName() does not work in WinUI3 #9842

HO-COOH opened this issue Jul 22, 2024 · 2 comments
Labels
area-Application bug Something isn't working team-Markup Issue for the Markup team

Comments

@HO-COOH
Copy link

HO-COOH commented Jul 22, 2024

Describe the bug

FindName() does not work in WinUI3, while the exact same code works in UWP.

Steps to reproduce the bug

  1. Create a new C++WinUI3 packaged project
  2. Use this xaml
    <StackPanel x:Name="Root" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center" Spacing="5">
        <Button x:Name="myButton" Click="myButton_Click">Click to load</Button>
        <Rectangle x:Name="DelayLoadRect" Fill="Green" Width="100" Height="50" x:Load="False" Loaded="Rectangle_Loaded"/>
    </StackPanel>
  1. Use this code
    void MainWindow::myButton_Click(IInspectable const&, RoutedEventArgs const&)
    {
        static bool IsLoaded = false;
        if (IsLoaded)
        {
            winrt::Microsoft::UI::Xaml::Markup::XamlMarkupHelper::UnloadObject(DelayLoadRect());
            myButton().Content(box_value(L"Click to load"));
        }
        else
        {
            myButton().Content(box_value(L"Click to unload"));
            auto delayLoadRect = Root().FindName(L"DelayLoadRect");
        }
        IsLoaded = !IsLoaded;
    }

    void MainWindow::Rectangle_Loaded(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e)
    {
        winrt::Microsoft::UI::Xaml::Controls::ContentDialog dialog;
        dialog.XamlRoot(Content().XamlRoot());
        dialog.Title(winrt::box_value(L"Loaded"));
        dialog.PrimaryButtonText(L"OK");
        dialog.ShowAsync();
    }
  1. Build and run, the green rect is not loaded. The dialog is not shown.

Repro here

Expected behavior

No response

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.5.5: 1.5.240627000

Windows version

Windows 11 (22H2): Build 22621

Additional context

No response

@HO-COOH HO-COOH added the bug Something isn't working label Jul 22, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Jul 22, 2024
@pratikone pratikone added team-Markup Issue for the Markup team area-Application labels Jul 23, 2024
@eduardobragaxz
Copy link

Try it on a page instead.

@HO-COOH
Copy link
Author

HO-COOH commented Jul 25, 2024

Try it on a page instead.

Moving it to a Page does work, but I think the fact that it does not work under Window needs to be documented.

@JesseCol JesseCol removed the needs-triage Issue needs to be triaged by the area owners label Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Application bug Something isn't working team-Markup Issue for the Markup team
Projects
None yet
Development

No branches or pull requests

4 participants