WPF : Set child window size programmatically
<p>I need to resize a child window when its parent is resized manually.
In order to do this, I made the following code on the parent window :</p>

<pre><code>SizeChanged += (sender, e) =&gt;
{
    if (e.PreviousSize.Width != 0 &amp;&amp; e.PreviousSize.Height != 0)
    {
        m_RatioX *= e.NewSize.Width / e.PreviousSize.Width;
        m_RatioY *= e.NewSize.Height / e.PreviousSize.Height;
    }
    WPFWindow p = ((WPFWindow)sender);
    foreach (WPFWindow w in p.OwnedWindows)
    {
        if (w.m_doStretch)
        {
            // this work fine
            w.Left *= m_RatioX / w.m_RatioX;
            w.Top *= m_RatioY / w.m_RatioY;
            w.Canvas.RenderTransform = new ScaleTransform(m_RatioX, m_RatioY);

            // but not for the size modification
            w.Width *= m_RatioX / w.m_RatioX;
            w.Height *= m_RatioY / w.m_RatioY;
            w.m_RatioX = m_RatioX;
            w.m_RatioY = m_RatioY;
        }
    }
};
</code></pre>

<p>The lines </p>

<pre><code>w.Width *= m_RatioX / w.m_RatioX;
w.Height *= m_RatioY / w.m_RatioY;
</code></pre>

<p>does not works in the sense that they have absolutely no effect on the child window size.</p>

<p>After some researchs I've also tried the following two alternatives, but the first also has no effect on the window size where the second crash with a <code>NullReferenceException</code>.</p>

<pre><code>// first alternative
Window.GetWindow(w).Width = Window.GetWindow(w).Width * m_RatioX / w.m_RatioX;
Window.GetWindow(w).Height = Window.GetWindow(w).Height * m_RatioY / w.m_RatioY;

// second one
Application.Current.MainWindow = w;
Application.Current.MainWindow.Width = Application.Current.MainWindow.Width * m_RatioX / w.m_RatioX;
Application.Current.MainWindow.Height = Application.Current.MainWindow.Height * m_RatioY / w.m_RatioY;
</code></pre>

<p>So, how should I modify the size of the child window so that its render is effectively resized ?</p>

<p><strong>EDIT :</strong></p>

<p>Some precisions :</p>

<ul>
<li>The <code>SizeChanged</code> handler is called only in the parent window.</li>
<li><code>m_RatioX</code> and <code>m_RatioY</code> default values are 1.</li>
</ul>