Wilson
Wilson

Reputation: 8768

Passing a variable to a window already open

Context: Creating a custom MessageBox with text input

How can I pass a variable back to my original window from my custom MessageBox window? I know how to do this when opening a new window, but not with one already open.

Upvotes: 0

Views: 132

Answers (1)

sa_ddam213
sa_ddam213

Reputation: 43596

Can you not just grab data from your message box when it closes

var msgBox = new MyMessageBox();
If (msgBox.ShowDialog(blah, blah, etc) == true)
{
   var dataBack = msgBox.PropertyThatHasInfo;
}

To return a DialogResult from you Window you can just set the DialogResult boollean depending on the user interaction

EG:

   public class MyMessageBox : Window
   {

        private void OK_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
   }

Upvotes: 3

Related Questions