2017-05-23 32 views
0

ContentDialog^をUWP C++アプリケーションで使用しようとしています。 MessageDialog^ を使えば、簡単にボタンを設定し、それらがUWP C++ ContentDialog PrimaryButtonCommandまたはPrimaryButtonClick

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)); 

に触れたとき、あなたは簡単に

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 
    } 
} 

によってCommandInvokedHandlerに送信された値が、しかし、コンテンツダイアログが異なり、完全に機能にアクセスすることができます呼び出すWindows::UI::Popups::UICommandコマンドすることができます。それは...私はどちらかのいくつかの(未知の奇妙な)理由Windows::UI::Xaml::Input::ICommand完全に異なるを使用してプロパティdialog->PrimaryButtonCommandを設定する必要があり、この

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->PrimaryButtonClickを使用する必要がありますか?

どこのC++のサンプルを見つけるのにも苦労しています。ドキュメンテーションは何も解決しません。

答えて

0

ContentDialogPrimaryButtonCommandまたはPrimaryButtonClickのいずれかを使用できます。プライマリボタンがタップされたときに両方とも呼び出されます。それらの違いは、PrimaryButtonClickeventであることですが、PrimaryButtonCommandは、タイプがICommandのプロパティです。 ICommandU​ICommandと同じではなく、MessageDialogで使用されていますが、全く異なる2つのものです。

ICommandは、XAMLバインディングでより多く使用されます。これを使用するには、ICommandインターフェイスを実装し、ビューモデルで使用します。詳細は、Executing commands in a view modelを参照してください。

そして、あなたの場合、あなたはコードビハインドでコンテンツダイアログを作成しているので、私はあなただけで、次のようなイベントハンドラメソッドでPrimaryButtonClickイベントをサブスクライブすることができると思うよう:

void MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) 
{ 
    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->PrimaryButtonClick += ref new Windows::Foundation::TypedEventHandler<Windows::UI::Xaml::Controls::ContentDialog ^, Windows::UI::Xaml::Controls::ContentDialogButtonClickEventArgs ^>(this, &MainPage::OnPrimaryButtonClick); 
    dialog->ShowAsync(); 
} 


void MainPage::OnPrimaryButtonClick(Windows::UI::Xaml::Controls::ContentDialog ^sender, Windows::UI::Xaml::Controls::ContentDialogButtonClickEventArgs ^args) 
{ 
    // Do something useful here 
} 
関連する問題