【发布时间】:2017-10-23 20:04:27
【问题描述】:
我正在尝试在 UWP C++ 应用程序中使用 ContentDialog^。与MessageDialog^
您可以轻松设置它们在触摸时调用的按钮和命令Windows::UI::Popups::UICommand
MessageDialog^ msg = ref new MessageDialog("Data changed - Save?");
msg->Title = "Warning";
// Add commands and set their callbacks.
UICommand^ continueCommand = ref new UICommand("Yes", ref new UICommandInvokedHandler(this, &MainPage::CommandInvokedHandler));
UICommand^ upgradeCommand = ref new UICommand("No", ref new UICommandInvokedHandler(this, &MainPage::CommandInvokedHandler));
UICommand^ cancelCommand = ref new UICommand("Cancel", ref new UICommandInvokedHandler(this, &MainPage::CommandInvokedHandler));
然后您可以轻松访问发送到CommandInvokedHandler 的值
void MainPage::CommandInvokedHandler(Windows::UI::Popups::IUICommand^ command)
{
// Display message
if (command->Label == "Yes") {
Save();
} else if (command->Label == "No") {
Skip();
} else if (command->Label == "Cancel") {
//do nothing
}
}
但是,内容对话框的工作方式完全不同。它是这样创建的
TextBox^ inputTextBox = ref new TextBox();
inputTextBox->AcceptsReturn = false;
inputTextBox->Height = 32;
ContentDialog^ dialog = ref new ContentDialog();
dialog->Content = inputTextBox;
dialog->Title = "Rename";
dialog->IsSecondaryButtonEnabled = true;
dialog->PrimaryButtonText = "Ok";
dialog->SecondaryButtonText = "Cancel";
dialog->ShowAsync();
我要么需要设置属性dialog->PrimaryButtonCommand,因为某些(未知的奇怪)原因使用完全不同的Windows::UI::Xaml::Input::ICommand...
或者我应该使用dialog->PrimaryButtonClick?
我在任何地方都很难找到任何 C++ 示例,但文档并没有说明任何内容。
【问题讨论】: