我是WinRT的新手。我正在将我的使用C++/CX编写的Windows UWP应用程序转换成C++/WinRT。我有一个C++/CX ref
类,其基本上执行与C#中Microsoft.VisualStudio.PlatformUI.DelegateCommand
类相同的操作。我的C++类实现了ICommand
接口,其中Execute
和CanExecute
回调由委托处理。头文件的简略代码如下:
public delegate void ExecuteDelegate(Platform::Object^ parameter);
public delegate bool CanExecuteDelegate(Platform::Object^ parameter);
public ref class DelegateCommand sealed :
Windows::UI::Xaml::DependencyObject,
Windows::UI::Xaml::Data::INotifyPropertyChanged,
public Windows::UI::Xaml::Input::ICommand
{
public:
DelegateCommand(ExecuteDelegate^ execute, CanExecuteDelegate^ canExecute);
.
.
.
private:
ExecuteDelegate^ m_executeDelegate = nullptr;
CanExecuteDelegate^ m_canExecuteDelegate = nullptr;
.
.
.
};
我的 DelegateCommand
类的典型实例从一个拥有 Execute
和 CanExecute
方法实现的类中,将一个弱指针和函数指针传递到构造函数中:
Commands::Instance->UndoCommand = ref new DelegateCommand(
ref new ExecuteDelegate(this, &SVGDocumentUserControl::ExecuteUndoCommand),
ref new CanExecuteDelegate(this, &SVGDocumentUserControl::CanExecuteUndoCommand));
我相信这是一个简单的问题,但从我的阅读中并不清楚,那么如何在C++/WinRT中定义两个C++/CX委托?
public delegate void ExecuteDelegate(Platform::Object^ parameter);
public delegate bool CanExecuteDelegate(Platform::Object^ parameter);
[编辑:我也在思考如何在*.idl文件中定义构造函数指针。]
感谢您的耐心等待。
winmd
格式),让您看到正确的原始声明吗? - Ben Voigt