title: WPF: How do I set the Owner Window of a Dialog shown by a UserControl?
body: <p>I've got a WPF application with these three types of things...</p>
  
  <ul>
  <li>WindowMain</li>
  <li>UserControlZack</li>
  <li>WindowModal</li>
  </ul>
  
  <p>UserControlZack1 sits on my WindowMain...</p>
  
  <pre><code>&lt;Window x:Class="WindowMain"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:local="clr-namespace:ProjectName"
          ...
          Name="WindowMain"&gt;
      &lt;Grid&gt;
          ...
          &lt;local:UserControlZack x:Name="UserControlZack1" ... /&gt;
          ...
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>UserControlZack1 displays a WindowModal dailog box...</p>
  
  <pre>
  Partial Public Class UserControlZack
  
     ...
  
      Private Sub SomeButton_Click(...)
          'instantiate the dialog box and open modally...
          Dim box As WindowModal = New WindowModal()
          box.Owner = ?????
          box.ShowDialog()
          'process data entered by user if dialog box is accepted...
          If (box.DialogResult.GetValueOrDefault = True) Then
              _SomeVar = box.SomeVar
              ...
          End If
      End Sub
  
  End Class
  </pre>
  
  <p>How do I set box.Owner to the correct Window, my running instance of WindowMain?</p>
  
  <p>I cannot use <code>box.Owner = Me.Owner</code>, because "'Owner' is not a member of 'ProjectName.UserControlZack'."</p>
  
  <p>I cannot use <code>box.Owner = Me.Parent</code>, because that returns a Grid, not the Window.</p>
  
  <p>I cannot use <code>box.Owner = WindowMain</code>, because "'WindowMain' is a type and cannot be used as an expression."</p>