WPFでモーダルダイアログを表示するために必要なことは何もありません。ちょうど(のは、クラス名がMyDialog
あるとしましょう)プロジェクトにWindow
を追加し、実行します。
var dialog = new MyDialog();
dialog.ShowDialog();
Window.ShowDialog
はモーダルな方法でウィンドウを示すの世話をします。
例:どこかにあなたのコードで
public class MyDialog : Window {
public MyDialog() {
this.InitializeComponent();
this.DialogResult = null;
}
public string SomeData { get; set; } // bind this to a control in XAML
public int SomeOtherData { get; set; } // same for this
// Attach this to the click event of your "OK" button
private void OnOKButtonClicked(object sender, RoutedEventArgs e) {
this.DialogResult = true;
this.Close();
}
// Attach this to the click event of your "Cancel" button
private void OnCancelButtonClicked(object sender, RoutedEventArgs e) {
this.DialogResult = false;
this.Close();
}
}
:
var dialog = new MyDialog();
// If MyDialog has properties that affect its behavior, set them here
var result = dialog.ShowDialog();
if (result == false) {
// cancelled
}
else if (result == true) {
// do something with dialog.SomeData here
}
出典
2011-01-04 12:31:49
Jon
すべてが順調に良いとどのようにあなたがinputDialogを定義するか、あなたは何を継承し、そのようなのですか? –
@Ingo:あなたは 'Window'から継承します。特別なことは何もありません。 – Jon
私は参照してください。どのチュートリアルでも、ShowDialogメソッドでBoolを返す方法と、入力にアクセスする方法などを教えていただけますか? –