title: Positioning a dialog window in WPF
body: <p>I have a command button that launches a separate window.  I'm using the MVVM Cross architecture, and so the window is fed through a command in the ViewModel.  The way that I've done this is a register a service in the UI layer that displays a window, and then in the command, to resolve that service and display the window:</p>
  
  <pre><code>public static void ShowMyWindow()
  {
      IShowMyWindowService myService = Mvx.Resolve&lt;IShowMyWindowService&gt;();        
  
      myService.ShowWindow();
  }
  </code></pre>
  
  <p>Then, in the service (which is in the UI layer):</p>
  
  <pre><code>public void ShowWindow()
  {
      Window myWindow = new Window();
      myWindow.Content = new MyUserControl();
  
      Application.Current.Dispatcher.Invoke(() =&gt;
      {
          myWindow.Owner = Application.Current.MainWindow;
  
          // Need to set x, y to the position of the button that invoked the command
          myWindow.Left = x;
          myWindow.Top = y;
  
          myWindow.ShowDialog();
      });
  }        
  </code></pre>
  
  <p>The problem that I have is that I want to show the new dialog in a position relative to the position of the command button that launched it.  Having done a bit of research, it looks like I need the <code>FrameworkElement.PointToScreen()</code> method, although what I can't determine is how to access this information without breaking the separation of concern.</p>
  
  <p>Am I going about this the correct way, or is there an easier way?  If i am, then how can I pas the framework element through the command?</p>