MessageBox with textbox WPF
-
I created a window with a field to set the name that the file will be saved. And with the code below I run inside the MainWindow.
var dialog = new windowFileName();
if (dialog.ShowDialog() == true) { MessageBox.Show(dialog.strFileName\_str); }
But I'm not getting check if the field is empty. I tried:
if (dialog.ShowDialog() == false)
{MessageBox.Show("Please, enter the name file");
dialog.txtFileName.Focus();
}But the dialog close and does not work.
-
I created a window with a field to set the name that the file will be saved. And with the code below I run inside the MainWindow.
var dialog = new windowFileName();
if (dialog.ShowDialog() == true) { MessageBox.Show(dialog.strFileName\_str); }
But I'm not getting check if the field is empty. I tried:
if (dialog.ShowDialog() == false)
{MessageBox.Show("Please, enter the name file");
dialog.txtFileName.Focus();
}But the dialog close and does not work.
juliogyn wrote:
But the dialog close and does not work.
Of course it does, because the tests you are making only happen after the
ShowDialog()
method returns. Check http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx[^] for full details of how this operates. You need to trap the events that cause the dialog to be closed, and add your tests there to prevent it closing until the correct data is entered by the user.Veni, vidi, abiit domum