没有重载函数的实例 winrt::Windows::UI::Xaml::Controls::Primitives::SelectorItem::Content 与参数列表匹配

No instance of overloaded function winrt::Windows::UI::Xaml::Controls::Primitives::SelectorItem::Content matches the argument list

在 C++/CX 中,我能够做到:

Windows::UI::Xaml::Controls::Primitives::SelectorItem item;
const wchar_t* str = L"someString";
item->Content = str;

但是,当我在 C++/WinRT 中执行等效操作时,

winrt::Windows::UI::Xaml::Controls::Primitives::SelectorItem item;
const wchar_t* str = L"someString";
item.Content(str);

我收到一个错误:

No instance of overloaded function winrt::Windows::UI::Xaml::Controls::Primitives::SelectorItem::Content matches the argument list.

我错过了什么?

Content 函数需要 IInspectable 类型的东西,wchar_t 不是。如果你传递“原语”,你需要把它们装箱。以下作品:

winrt::Windows::UI::Xaml::Controls::Primitives::SelectorItem item;
const wchar_t* str = L"someString";
item.Content(box_value(str));