Return an object from a popup window

Viewed 72034

I have a Window which pop-ups another Window. I want the second Window to be able to return an object to the first Window when a button is pressed. How would I do this?

6 Answers

I did it like that.

In parent window make a corresponding ClosingEvent like this :

private void NewWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
        NewWindow nw = (NewWindow)sender;

        object Receiver = nw.Sender;
    }

...and in the child window change your code implement the "sender" like this :

    public partial class NewWindow : Window
{
    public object Sender { get; set; }

    public NewWindow()
    {
        InitializeComponent();

        Sender = objectYouWantToSend;
    }
}

So when you put data into the object "Sender" in child window, while closing this window will put the data into the "Receiver" variable.

I hope, this helps.

You can simply call any method of the popup window like this:

int value = 0;
if ((bool)poupWindow.ShowDialog() == true) {
  value = poupWindow.GetValue();
}
Related