microsoft / microsoft-ui-xaml

WinUI: a modern UI framework with a rich set of controls and styles to build dynamic and high-performing Windows applications.
MIT License
6.38k stars 683 forks source link

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

Open HO-COOH opened 2 years ago

HO-COOH commented 2 years ago

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

Device form factor

No response

Windows version

Windows Insider Build (xxxxx)

Additional context

No response

HO-COOH commented 2 years ago

Quick workaround I found, add this in your idl

void UnloadObject(Windows.UI.Xaml.DependencyObject object);
github-actions[bot] commented 1 year ago

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.

HO-COOH commented 1 year ago

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

JesseCol commented 10 months ago

Hi, does this issue repro in WinAppSDK? Thanks!

HO-COOH commented 10 months ago

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'
JesseCol commented 10 months ago

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?

HO-COOH commented 10 months ago

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.

tom-huntington commented 1 week ago

Quick workaround I found, add this in your idl

IInspectable FindName(String name);

It didn't work for FindName :( https://github.com/microsoft/microsoft-ui-xaml/issues/9842