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

In C++ FindName wont reload an object that has been UnloadObjected #10179

Open
tom-huntington opened this issue Nov 19, 2024 · 2 comments
Open
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners

Comments

@tom-huntington
Copy link

tom-huntington commented Nov 19, 2024

Describe the bug

This doesn't happen in C#

This also happens if we replace the call to UnloadObject with myStackPanel.Children().ReplaceAll({});. This is similar to #10176

Steps to reproduce the bug

<Window ...>
    <StackPanel x:Name="myStackPanel" Orientation="Vertical"  VerticalAlignment="Center">
            <Button x:Load="True" x:Name="myButton" Click="myButton_Click">Click Me</Button>
    </StackPanel>
</Window>
void MainWindow::myButton_Click(IInspectable const&, RoutedEventArgs const&)
{
    UnloadObject(myButton());
    winrt::check_bool(!myButton());
    auto r = myStackPanel().FindName(L"myButton");
    winrt::check_bool(!r); // wrong
    winrt::check_bool(!myButton()); // wrong
}
private void myButton_Click(object sender, RoutedEventArgs e)
{
    UnloadObject(myButton);
    Debug.Assert(myButton == null);
    var r = myStackPanel.FindName("myButton");
    Debug.Assert(r != null); // good
    Debug.Assert(myButton != null); // good
}

NuGet package version

WinUI 3 - Windows App SDK 1.6.3: 1.6.241114003

Windows version

Windows 11 (21H2): Build 22000

Additional context

No response

@tom-huntington tom-huntington added the bug Something isn't working label Nov 19, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Nov 19, 2024
Copy link

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!

Open similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@tom-huntington
Copy link
Author

tom-huntington commented Nov 19, 2024

https://learn.microsoft.com/en-us/windows/uwp/xaml-platform/x-load-attribute

when the element is not loaded, its memory is released and internally a small placeholder is used to mark its place in the visual tree.

So I'm guessing this placeholder is being removed. When I iterate over Panel.Children the placeholders are not there. But calling UIElementCollection.ReplaceAll removes them, as per my other issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners
Projects
None yet
Development

No branches or pull requests

1 participant