microsoft-ui-xaml
microsoft-ui-xaml copied to clipboard
Compile error when using x:Load and x:Bind with C++/WinRT
Describe the bug
<Button x:Name="ChooseFile" Content="Add" Click="Button_Click" x:Load="{x:Bind Show}"/>
[default_interface]
runtimeclass MainPage : Windows.UI.Xaml.Controls.Page
{
MainPage();
Boolean Show{ get; };
}
Steps to reproduce the bug
- Add any control to a
Page, with{x:Load}binding to a boolean value - Compiler error
1>C:\Users\Peter\source\repos\UwpCpp\Generated Files\MainPage.xaml.g.hpp(224,35): error C2039: 'UnloadObject': is not a member of 'winrt::UwpCpp::MainPage'
Expected behavior
No response
Screenshots

NuGet package version
Microsoft.UI.Xaml 2.8.0
Windows app type
- [X] UWP
- [ ] Win32
Device form factor
No response
Windows version
Windows Insider Build (xxxxx)
Additional context
No response
Quick workaround I found, add this in your idl
void UnloadObject(Windows.UI.Xaml.DependencyObject object);
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This is still reproducible with WinUI 2.8.5. Amazing to see how this seemingly a must-to-have feature got not attention.
Hi, does this issue repro in WinAppSDK? Thanks!
Hi, does this issue repro in WinAppSDK? Thanks!
Yes, if the root object is a Window, that is
<Window
....
<Button x:Load="{x:Bind Show, Mode=OneWay}"/>
You get
'FindName': is not a member of 'winrt::WinUI3Cpp2::MainWindow'
Thank you HO-COOH, this seems like a different issue, no? Xaml's Window is not a FrameworkElement, and doesn't have a FindName() function. See for example: 7305. Do you still see a problem with Page in WinAppSDK?
Thank you HO-COOH, this seems like a different issue, no? Xaml's Window is not a FrameworkElement, and doesn't have a FindName() function. See for example: 7305. Do you still see a problem with Page in WinAppSDK?
It's a differenent cause yes, but it's the same issue as the title. C# winui3 project builds fine.