microsoft / WindowsAppSDK

The Windows App SDK empowers all Windows desktop apps with modern Windows UI, APIs, and platform features, including back-compat support, shipped via NuGet.
https://docs.microsoft.com/windows/apps/windows-app-sdk/
MIT License
3.85k stars 323 forks source link

error C3861: 'weak_from_this': identifier not found in file xxx.xaml.g.hpp #4643

Closed shelllet closed 2 months ago

shelllet commented 3 months ago

Describe the bug

Compare the following two code snippets:

1

template <typename D, typename ... I>
 void MainWindowT<D, I...>::Connect(int32_t connectionId, IInspectable const& target)
 {
     switch (connectionId)
     {
     case 2:
         {
             auto targetElement = target.as<::winrt::Microsoft::UI::Xaml::Controls::Button>();
             this->myButton(targetElement);
             auto weakThis = ::winrt::make_weak<class_type>(*this);
             targetElement.Click([weakThis](::winrt::Windows::Foundation::IInspectable const& p0, ::winrt::Microsoft::UI::Xaml::RoutedEventArgs const& p1){
                 if (auto t = weakThis.get())
                 {
                     ::winrt::get_self<D>(t)->myButton_Click(p0, p1);
                 }
             });
         }
         break;
     }
     _contentLoaded = true;
 }

2

 obj4.RegisterPropertyChangedCallback(...,
     [weakThis{ weak_from_this() }, this] (DependencyObject const& sender, DependencyProperty const& prop)
     {
         if (auto strongThis{ weakThis.lock() })
         {
             if (IsInitialized())
             {
                 // Update Two Way binding
                 if (GetDataRoot() != nullptr)
                 {
                     if (GetDataRoot().Point() != nullptr)
                     {
                         GetDataRoot().Point().Y(obj4.Value());
                     }
                 }
             }
         }
     });

Steps to reproduce the bug

  1. upgrade to 1.6 preview1
  2. create winui project.
  3. add property
  4. compile code.

Expected behavior

No response

Screenshots

image

NuGet package version

Windows App SDK 1.6 Preview 1: 1.6.240807006-preview1

Packaging type

Unpackaged

Windows version

Windows 11 version 22H2 (22621, 2022 Update)

IDE

Visual Studio 2022

Additional context

No response

codendone commented 3 months ago

If you're using /permissive- compiler flag, switching to /permissive should unblock you. We'll get this fixed for the next 1.6 build. (internal tracking bug)