dialogresult

Why is DialogResult a nullable bool in WPF?

蹲街弑〆低调 提交于 2019-12-01 13:49:26
问题 Can anyone think of a good explanation for the fact that result of a dialog is a nullable bool in WPF? This has always baffled me. In WinForms it was an enum type and that made a lot more sense to me. 回答1: In my opinion this was done because in most cases you don't need the generalized specialized options like Retry or Ignore. If you need more than OK/Cancel, you are supposed to use some kind of task dialog, e.g. with written-out answers. That way, you're not limited to the few enum values

Where is Button.DialogResult in WPF?

孤人 提交于 2019-11-30 11:29:13
In System.Windows. Forms .Button there is a property DialogResult , where is this property in the System.Windows. Controls .Button (WPF)? There is no built-in Button.DialogResult, but you can create your own (if you like) using a simple attached property: public class ButtonHelper { // Boilerplate code to register attached property "bool? DialogResult" public static bool? GetDialogResult(DependencyObject obj) { return (bool?)obj.GetValue(DialogResultProperty); } public static void SetDialogResult(DependencyObject obj, bool? value) { obj.SetValue(DialogResultProperty, value); } public static

Using DialogResult Correctly

為{幸葍}努か 提交于 2019-11-27 04:46:32
In an answer to a recent question I had ( Here ), Hans Passant stated that I should set the DialogResult to close my forms instead of form.Close() although I cannot seem to find out why? If I've read correctly, the MSDN documentation states that doing this will just hide the form instead of correctly disposing it which I believed .Close() to do? Extract from documentation. The Close method is not automatically called when the user clicks the Close button of a dialog box or sets the value of the DialogResult property. Instead, the form is hidden and can be shown again without creating a new

How do I create a message box with “Yes”, “No” choices and a DialogResult?

◇◆丶佛笑我妖孽 提交于 2019-11-26 21:14:44
I want to make simple Yes/No choiced MessageBox, but I think it is nonsense to design a form for that. I thought I could use MessageBox, add buttons, etc. to accomplish this. It is simple, but since there is no DialogResult returned, how do I retrieve the result? This should do it: DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo); if(dialogResult == DialogResult.Yes) { //do something } else if (dialogResult == DialogResult.No) { //do something else } DialogResult dr = MessageBox.Show("Are you happy now?", "Mood Test", MessageBoxButtons.YesNo); switch

How do I create a message box with “Yes”, “No” choices and a DialogResult?

随声附和 提交于 2019-11-26 09:04:54
问题 I want to make simple Yes/No choiced MessageBox, but I think it is nonsense to design a form for that. I thought I could use MessageBox, add buttons, etc. to accomplish this. It is simple, but since there is no DialogResult returned, how do I retrieve the result? 回答1: This should do it: DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo); if(dialogResult == DialogResult.Yes) { //do something } else if (dialogResult == DialogResult.No) { //do something