gpt4 book ai didi

c# - 如何在 CLI::C++ 中使用委托(delegate) - 匿名委托(delegate)?

转载 作者:行者123 更新时间:2023-11-30 22:25:51 25 4
gpt4 key购买 nike

我有一个 C++/CLI 应用程序 - 我使用 MVVM 模式。
我经常希望它能将它的事件发布到主 GUI。我已经在 GUI 和按钮事件之间建立了连接,所以如果引发按钮事件,我可以关闭对话框 - 但我正在努力将语法从 C# 转换为 C++:

 viewModel->OKButtonCommand += delegate
{
dialogResult = System::Windows::Forms::DialogResult::OK;
dlg->Close();
};

viewModel->CancelButtonCommand += delegate
{
dialogResult = System::Windows::Forms::DialogResult::Cancel;
dlg->Close();
};

最佳答案

C++/CLI 中没有匿名委托(delegate)。您必须将委托(delegate)转换为普通类方法并以这种方式引用它。

关于c# - 如何在 CLI::C++ 中使用委托(delegate) - 匿名委托(delegate)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12127688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com