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

XamlMarkupHelper.UnloadObject gives exception #9819

Open
HO-COOH opened this issue Jul 16, 2024 · 3 comments
Open

XamlMarkupHelper.UnloadObject gives exception #9819

HO-COOH opened this issue Jul 16, 2024 · 3 comments
Labels
bug Something isn't working documentation An issue with existing documentation or a request for documenation of a new topic team-Markup Issue for the Markup team

Comments

@HO-COOH
Copy link

HO-COOH commented Jul 16, 2024

Describe the bug

I am trying to unload a child control inside my templated control using Windows.UI.Xaml.Markup.XamlMarkupHelper.UnloadObject (UWP) and Microsoft.UI.Xaml.Markup.XamlMarkupHelper.UnloadObject (Winui3) as documented here. But I got exceptions:

WinRT originate error - 0x80070057 : 'The parameter is incorrect.'

Steps to reproduce the bug

  1. Create a new C++WinUI3 project (Packaged)
  2. Create a new templated control, add a DependencyProperty called IsLoading. And write code when IsLoading==false, call this api to unload a component.
  3. In MainWindow.xaml, add a ToggleSwitch and this new templated control, bind the IsLoading to the ToggleSwitch.IsOn

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

This issue happens on both UWP & WinUI3. If I am doing anything wrong, please update the documentation!

@HO-COOH HO-COOH added the bug Something isn't working label Jul 16, 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 16, 2024
@codendone codendone added the team-Markup Issue for the Markup team label Jul 16, 2024
@codendone
Copy link
Contributor

Do you have x:Load set on the element? I think that may be required in order to use XamlMarkupHelper.UnloadObject.

@HO-COOH
Copy link
Author

HO-COOH commented Jul 16, 2024

Do you have x:Load set on the element? I think that may be required in order to use XamlMarkupHelper.UnloadObject.

Adding a x:Load="False" then loading it in code solves the issue (but please, add it in UnloadObject's remark section in the doc). This is from the UWP doc about x:Load.

The UI element attributed with x:Load can be loaded and unloaded via code, or using an x:Bind expression.

This says NOTHING about needing to set it to False then loaded in code, in order to be able to unload. Setting it to True you will still get the exceptions.

@codendone codendone added documentation An issue with existing documentation or a request for documenation of a new topic and removed needs-triage Issue needs to be triaged by the area owners labels Jul 16, 2024
@codendone
Copy link
Contributor

I agree the docs need to be clarified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation An issue with existing documentation or a request for documenation of a new topic team-Markup Issue for the Markup team
Projects
None yet
Development

No branches or pull requests

2 participants