【发布时间】:2019-01-18 00:30:21
【问题描述】:
我正在尝试在 C++/WinRT 中执行 data {Binding} via ICustomProperty(Microsoft 文档中没有可用的示例),如下所示:
#include "winrt\Windows.UI.Xaml.Data.h"
using namespace winrt;
using namespace winrt::Windows::UI::Xaml::Data;
struct MyCustomProperty : winrt::implements<MyCustomProperty, ICustomProperty>
{
// To be implemented
};
static MyCustomProperty TitleProperty;
struct MyCustomObject : winrt::implements<MyCustomObject, ICustomPropertyProvider>
{
ICustomProperty GetCustomProperty(winrt::hstring name)
{
return TitleProperty.try_as<ICustomProperty>();
}
// Other methods omitted
};
很遗憾,出现编译错误:
错误 C2039:“try_as”:不是“MyCustomProperty”的成员
请注意,简单的return TitleProperty; 不起作用。我该如何解决这个问题?
【问题讨论】: