如何在WindowsPhone 8.1 中将PrimaryButtonCommad 添加到ContentDialog?

How to add PrimaryButtonCommad to ContentDialog in WindowsPhone 8.1?

我在 ContentDialog 中显示一个 TextBox,当我按确定时,我想获取文本框的值并调用一个方法。我找不到任何与之相关的东西。这是我的代码。

 var box = new ContentDialog()
                    {
                            Title = "File Name",                                
                            Content = fileName,
                            PrimaryButtonText = "Ok",
                            PrimaryButtonCommand = ,
                            SecondaryButtonText = "Cancel"
                    };

                    await box.ShowAsync(); 

PrimaryButtonCommand 是一个 属性,您可以在其中放置一个具有 ICommand 接口的对象。如果你已经添加了一个 BasicPage 到你的项目,那么 VS 应该也添加 Common 文件夹和一些模板,在那里你会发现一个 RelayCommand class,您可以将其用于您的目的,示例如下所示:

private async void secondBtn_Click(object sender, RoutedEventArgs e)
{
    var box = new ContentDialog()
            {
                Title = "File Name",
                Content = fileName,
                PrimaryButtonText = "Ok",
                PrimaryButtonCommand = new RelayCommand(myAction),
                SecondaryButtonText = "Cancel"
            };
    await box.ShowAsync();
}

private async void myAction()
{
    await (new MessageDialog("User clicked ok")).ShowAsync();
}