我在ContentDialog中显示一个TextBox,当我按下确定时,我想获取文本框的值并调用方法。我找不到任何与之相关的东西。这是我的代码。
var box = new ContentDialog()
{
Title = "File Name",
Content = fileName,
PrimaryButtonText = "Ok",
PrimaryButtonCommand = ,
SecondaryButtonText = "Cancel"
};
await box.ShowAsync();
答案 0 :(得分:0)
PrimaryButtonCommand是一个属性,您可以在其中放置一个具有 ICommand 接口的对象。如果您已将 BasicPage 添加到项目中,那么VS还应该添加 Common 文件夹和一些模板,在那里您将找到 RelayCommand 类,您可以将它用于您的目的,样本可以如下所示:
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();
}