Confirmation Box Code Error
-
Friday, April 06, 2012 4:42 PM
I'm setting up a confirmation box for clearing out a .txt file filled with raw data. Whether or not the action can complete is dependent on whether the "write data to file" box is checked- otherwise, you're going to try to delete something that doesn't exist. I'm getting an error:
Error 1 'System.Nullable<bool>' does not contain a definition for 'Yes' and no extension method 'Yes' accepting a first argument of type 'System.Nullable<bool>' could be found (are you missing a using directive or an assembly reference?)
while using this chunk of code:
private void reset_data_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("This operation will clear the .txt file. It cannot be undone.","Do you wish to continue?", MessageBoxButton.YesNo)==DialogResult.Yes) { } else if(chkOutput.IsChecked == false) { MessageBox.Show("No output file was created at the beginning of this program. This operation will have no effect"); } }
It's not happy about the "DialogResult.Yes". How do I fix this? I saw this particular bit of code posted quite a bit on the web... it's a fairly simple operation, so what am I doing wrong?
- Moved by CoolDadTxMVP Friday, April 06, 2012 5:09 PM WPF related (From:Visual C# General)
All Replies
-
Friday, April 06, 2012 4:58 PMThe MessageBox.Show method in WPF returns a value of the MessageBoxResult enumeration, so instead of DialogResult.Yes you must use MessageDialogResult.Yes.
Marco Minerva [MCPD]
Blog: http://blogs.ugidotnet.org/marcom
Twitter: @marcominerva- Edited by Marco MinervaMicrosoft Community Contributor Friday, April 06, 2012 4:59 PM
-
Friday, April 06, 2012 5:29 PM
That eliminates the error, but the error
Error 1 The name 'MessageDialogResult' does not exist in the current context
Appears in its place. I suppose I need to initialize this? Or is it some other issue? -
Friday, April 06, 2012 5:33 PM
I have confused the enumeration name the second time I have written it :-)
The correct value is MessageBoxResult.Yes.
Marco Minerva [MCPD]
Blog: http://blogs.ugidotnet.org/marcom
Twitter: @marcominerva- Edited by Marco MinervaMicrosoft Community Contributor Friday, April 06, 2012 5:39 PM
- Edited by Marco MinervaMicrosoft Community Contributor Friday, April 06, 2012 5:39 PM
-
Saturday, April 07, 2012 7:46 AM
Use this:
if (MessageBox.Show("Anwendung Beenden?", "Frage", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { textBlockEF00STZ1A.Text = "Beenden angeklickt"; } else { this.Close(); }Best Regards
Bernd
- Marked As Answer by Sheldon _XiaoModerator Thursday, April 19, 2012 9:26 AM

