cppwinrt A subclass of Panel (or other class),需要什么构造函数?

cppwinrt A subclass of Panel (or other class),What constructors are needed?

对不起,我的英语不是很好。 我有一个这样的class

   struct WrapPanel :winrt::Windows::UI::Xaml::Controls::PanelT<WrapPanel>
   {
   public:
       WrapPanel(std::nullptr_t) {};
       // other code.....
   }

在其他 class 中使用

    WrapPanel wrapPanel{ ItemsPanelRoot().try_as<WrapPanel>()};
    //Error C2440   'initializing': cannot convert from 'initializer list' to 'WrapPanel'   

喜欢: https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/move-to-winrt-from-cx 从基本运行时 class 转换为派生运行时

如果您在 C++/WinRT 中编写运行时 class,您将在不同的命名空间中获得多个具有相同名称的 class。假设有一个名为 NS1 的命名空间,其中有一个名为 WrapPanel 的运行时 class,您将得到 winrt::NS1::WrapPanelwinrt::NS1::implementation::WrapPanelwinrt::NS1::factory_implementation::WrapPanel.第一个是运行时class的"projection",我们平时用的;第二个是 "implementation",它实现了运行时 class;第三个是 "factory",被 module.g.cpp.

使用

如果将基础 class 转换为衍生基础,则应使用 "projection"。看来你用过"implementation".