microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

Compile error when using x:Load and x:Bind with C++/WinRT

Open HO-COOH opened this issue 3 years ago • 9 comments

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

  1. Add any control to a Page, with {x:Load} binding to a boolean value
  2. 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

image

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

HO-COOH avatar Aug 09 '22 20:08 HO-COOH

Quick workaround I found, add this in your idl

void UnloadObject(Windows.UI.Xaml.DependencyObject object);

HO-COOH avatar Aug 10 '22 08:08 HO-COOH

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.

github-actions[bot] avatar Jul 29 '23 16:07 github-actions[bot]

This is still reproducible with WinUI 2.8.5. Amazing to see how this seemingly a must-to-have feature got not attention.

HO-COOH avatar Aug 01 '23 02:08 HO-COOH

Hi, does this issue repro in WinAppSDK? Thanks!

JesseCol avatar Jan 17 '24 21:01 JesseCol

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'

HO-COOH avatar Jan 18 '24 02:01 HO-COOH

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?

JesseCol avatar Jan 18 '24 19:01 JesseCol

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.

HO-COOH avatar Jan 19 '24 02:01 HO-COOH