WPF 用ShowDialog的方法显示窗口的返回值

using System;
using System.Windows;
using System.Windows.Controls;

namespace CSharp
{
    public partial class DialogBox : Window
    {
        public DialogBox()
        {
            InitializeComponent();
        }

        // The accept button is a button whose IsDefault property is set to true.
        // This event is raised whenever this button is clicked, or the ENTER key
        // is pressed.
        void acceptButton_Click(object sender, RoutedEventArgs e)
        {
            // Accept the dialog and return the dialog result
            this.DialogResult = true;
        }
    }
}

 
  

只要设置了DialogResult属性(true或false),窗口就会退出,ShowDialog()的返回值就是DialogResult,然后通过判断DialogResult是true还是false来确定用户意愿。

你可能感兴趣的:(2014,C#,C#,wpf)