2015-07-03 47 views
0

我在ContentDialog中顯示一個TextBox,當我按OK時,我想獲得文本框的值並調用一個方法。我找不到與之相關的任何內容。這是我的代碼。如何在WindowsPhone 8.1中添加PrimaryButtonCommad到ContentDialog?

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

        await box.ShowAsync(); 

回答

0

PrimaryButtonCommand是一個屬性,你可以放在那裏它有一個的ICommand接口對象。如果你增加了一個BasicPage到您的項目,然後VS還要補充常見文件夾一些模板,在那裏你會找到一個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(); 
} 
+0

它的工作感謝:) – Wahib

相關問題