How can I get a reference to the Window that calls a method, and use that to assign the Owner?
<p>How can I get the calling object inside a called method?</p>

<p>I've had to create a custom MessageBox, which is created as follows:</p>

<pre><code>public static class MsgBox
{
    public static MessageBoxResult Show(string messageBoxText)
    {
        var msg = new CustomMessageBoxWindow(messageBoxText);
        msg.ShowDialog();

        return msg.Result;
    }
}
</code></pre>

<p>I now need to specify an owner for this MessageBox. I can do this by forcing the developer to pass in the calling object, e.g.</p>

<pre><code>public static MessageBoxResult Show(string messageBoxText, Window owner)
</code></pre>

<p>and set the owner as follows</p>

<pre><code>msg.Owner = owner;
</code></pre>

<p>But this means having to change a lot of calls in a lot of places. It's doable, but it's not ideal. Ideally, I'd be able to find out what class called the MessageBox from inside the Show() method and set it without having to pass any new parameters, e.g.</p>

<pre><code>public static MessageBoxResult Show(string messageBoxText)
{
    var msg = new CustomMessageBoxWindow(messageBoxText);
    msg.ShowDialog();

    var owner = // somehow get the calling Window;
    msg.Owner = owner;

    return msg.Result;
}
</code></pre>
