title: XAML user control / window sizing
body: <p>I've created a basic framework that lets me display views within a modal dialog. The "container" window looks something like this (just the XAML pertinent to my problem):-</p>
  
  <pre><code>&lt;Window SizeToContent="WidthAndHeight"
          ResizeMode="{Binding DialogResizeMode}"&gt;        
      &lt;DockPanel LastChildFill="True"&gt;
          &lt;Border DockPanel.Dock="Bottom"&gt;
              &lt;!-- This is where the buttons are rendered --&gt;
          &lt;/Border&gt;
  
          &lt;ContentControl /&gt;
      &lt;/DockPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Views (UserControls) are placed in the <code>ContentControl</code>, with a typical view looking something like this:-</p>
  
  <pre><code>&lt;UserControl ..the usual stuff..
               Width="500"
               Height="400"&gt;
     &lt;!-- etc. --&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>By setting the width and height, it means the view can effectively control the dimensions of the modal dialog (due to the container window's <code>SizeToContent="WidthAndHeight"</code> setting).</p>
  
  <p>The problem is, I now need to make the dialog resizable in some scenarios. If I set the parent Window's <code>ResizeMode</code> to <code>CanResize</code>, the user control remains at its fixed size in the centre of the dialog as the window is resized.</p>
  
  <p>I suspect I'll need to use a different approach to setting the initial window size, such as providing the width and height for the window to bind to (unless I'm missing a simple solution). Any suggestions?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I've found a solution by removing the <code>SizeToContent</code> option from the parent window, and removing the Width &amp; Height from the user control XAMl. I now set the window size from the user control's Loaded event:-</p>
  
  <pre><code>var window = Window.GetWindow(this);
  window.Width = 500;
  window.Height = 400;
  </code></pre>
  
  <p>It feels a bit hacky though - it would be nice if this could be accomplished using a XAML-only solution.</p>