microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.36k stars 678 forks source link

x:Bind with TwoWay mode cause error C3779 in C++20 or latest #8503

Open ACGNnsj opened 1 year ago

ACGNnsj commented 1 year ago

Describe the bug

It works well with OneWay mode, but not with TwoWay mode. Logs:

0>WindowConfigPage.xaml.g.hpp(131,65): Error C3779 : “winrt::impl::consume_OCR_IWindowConfigPage<winrt::OCR::IWindowConfigPage>::SharedItem”: 要使用将会返回“auto”的函数,必须首先定义此函数 (编译源文件 Generated Files\XamlTypeInfo.g.cpp)
0>OCR.0.h(514,28): Message  : 参见“winrt::impl::consume_OCR_IWindowConfigPage<winrt::OCR::IWindowConfigPage>::SharedItem”的声明 (编译源文件 Generated Files\XamlTypeInfo.g.cpp)
0>WindowConfigPage.xaml.g.hpp(363,6): Message  : 查看对正在编译的 类 模板 实例化“winrt::OCR::implementation::WindowConfigPageT<D,I...>::WindowConfigPage_obj1_Bindings”的引用 (编译源文件 Generated Files\XamlTypeInfo.g.cpp)
0>WindowConfigPage.xaml.g.hpp(152,65): Error C3779 : “winrt::impl::consume_OCR_IWindowConfigPage<winrt::OCR::IWindowConfigPage>::SharedItem”: 要使用将会返回“auto”的函数,必须首先定义此函数 (编译源文件 Generated Files\XamlTypeInfo.g.cpp)
0>OCR.0.h(514,28): Message  : 参见“winrt::impl::consume_OCR_IWindowConfigPage<winrt::OCR::IWindowConfigPage>::SharedItem”的声明 (编译源文件 Generated Files\XamlTypeInfo.g.cpp)
0>WindowConfigPage.xaml.g.hpp(173,65): Error C3779 : “winrt::impl::consume_OCR_IWindowConfigPage<winrt::OCR::IWindowConfigPage>::SharedItem”: 要使用将会返回“auto”的函数,必须首先定义此函数 (编译源文件 Generated Files\XamlTypeInfo.g.cpp)
0>OCR.0.h(514,28): Message  : 参见“winrt::impl::consume_OCR_IWindowConfigPage<winrt::OCR::IWindowConfigPage>::SharedItem”的声明 (编译源文件 Generated Files\XamlTypeInfo.g.cpp)
0>WindowConfigPage.xaml.g.hpp(194,65): Error C3779 : “winrt::impl::consume_OCR_IWindowConfigPage<winrt::OCR::IWindowConfigPage>::SharedItem”: 要使用将会返回“auto”的函数,必须首先定义此函数 (编译源文件 Generated Files\XamlTypeInfo.g.cpp)
0>OCR.0.h(514,28): Message  : 参见“winrt::impl::consume_OCR_IWindowConfigPage<winrt::OCR::IWindowConfigPage>::SharedItem”的声明 (编译源文件 Generated Files\XamlTypeInfo.g.cpp)

Steps to reproduce the bug

ViewModel definitions: SharedItem.idl SharedItem.h SharedItem.cpp The problem would occur if modes here were switched to TwoWay. WindowConfigPage.xaml

Expected behavior

The compilation would succeed with bindings under TwoWay mode.

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.3.1: 1.3.230502000

Windows version

Windows Insider Build (xxxxx)

Additional context

Problematic codes in generated file 'WindowConfigPage.xaml.g.hpp':

void Connect(int32_t connectionId, IInspectable const& target) override
        {
            switch(connectionId)
            {
            case 2: // WindowConfigPage.xaml line 22
                {
                    auto targetElement = target.as<::winrt::Microsoft::UI::Xaml::Controls::NumberBox>();
                    obj2 = targetElement;
                    obj2.RegisterPropertyChangedCallback(::winrt::Microsoft::UI::Xaml::Controls::NumberBox::ValueProperty(),
                        [this] (DependencyObject const& sender, DependencyProperty const& prop)
                        {
                            if (IsInitialized())
                            {
                                // Update Two Way binding
                                if (GetDataRoot() != nullptr)
                                {
                                    if (GetDataRoot().SharedItem() != nullptr)
                                    {
                                        GetDataRoot().SharedItem().Width(obj2.Value());
                                    }
                                }
                            }
                        });
                }
                break;
            case 3: // WindowConfigPage.xaml line 23
                {
                    auto targetElement = target.as<::winrt::Microsoft::UI::Xaml::Controls::NumberBox>();
                    obj3 = targetElement;
                    obj3.RegisterPropertyChangedCallback(::winrt::Microsoft::UI::Xaml::Controls::NumberBox::ValueProperty(),
                        [this] (DependencyObject const& sender, DependencyProperty const& prop)
                        {
                            if (IsInitialized())
                            {
                                // Update Two Way binding
                                if (GetDataRoot() != nullptr)
                                {
                                    if (GetDataRoot().SharedItem() != nullptr)
                                    {
                                        GetDataRoot().SharedItem().Height(obj3.Value());
                                    }
                                }
                            }
                        });
                }
                break;
            case 4: // WindowConfigPage.xaml line 24
                {
                    auto targetElement = target.as<::winrt::Microsoft::UI::Xaml::Controls::NumberBox>();
                    obj4 = targetElement;
                    obj4.RegisterPropertyChangedCallback(::winrt::Microsoft::UI::Xaml::Controls::NumberBox::ValueProperty(),
                        [this] (DependencyObject const& sender, DependencyProperty const& prop)
                        {
                            if (IsInitialized())
                            {
                                // Update Two Way binding
                                if (GetDataRoot() != nullptr)
                                {
                                    if (GetDataRoot().SharedItem() != nullptr)
                                    {
                                        GetDataRoot().SharedItem().X(obj4.Value());
                                    }
                                }
                            }
                        });
                }
                break;
            case 5: // WindowConfigPage.xaml line 25
                {
                    auto targetElement = target.as<::winrt::Microsoft::UI::Xaml::Controls::NumberBox>();
                    obj5 = targetElement;
                    obj5.RegisterPropertyChangedCallback(::winrt::Microsoft::UI::Xaml::Controls::NumberBox::ValueProperty(),
                        [this] (DependencyObject const& sender, DependencyProperty const& prop)
                        {
                            if (IsInitialized())
                            {
                                // Update Two Way binding
                                if (GetDataRoot() != nullptr)
                                {
                                    if (GetDataRoot().SharedItem() != nullptr)
                                    {
                                        GetDataRoot().SharedItem().Y(obj5.Value());
                                    }
                                }
                            }
                        });
                }
                break;
            }
        }

WindowConfigPage.xaml.g.zip

ACGNnsj commented 1 year ago

Still a problem in the new version. Can anyone help?

JesseCol commented 1 year ago

Hi ACGNnsj, when I click on your link for WindowConfigPage.xaml, I get a 404 error. Is there some other way to find your repro? Thanks!

ACGNnsj commented 1 year ago

Hi ACGNnsj, when I click on your link for WindowConfigPage.xaml, I get a 404 error. Is there some other way to find your repro? Thanks!

Thanks for your reply. I've updated the links, and you would get this error when changing existing x:Bind mode to TwoWay.