I'm trying to use ContentDialog^ in a UWP C++ app. With MessageDialog^
you can easily set the buttons and commands Windows::UI::Popups::UICommand they invoke when touched
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));
then you can easily access the value sent to the CommandInvokedHandler by
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
}
}
However, the content dialog works completely differently. It's created like this
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();
I either need to set the property dialog->PrimaryButtonCommand that for some (unknown bizarre) reason uses the completely different Windows::UI::Xaml::Input::ICommand...
Or should I use the dialog->PrimaryButtonClick?
I'm struggling to find any C++ examples anywhere and the documentation doesn't clear anything up.