title: Convert a MultipleMonitor Application From WinForms to WPF
body: <p>I've got a little problem and tried to solve it now for nearly 6 to 8 hours but I didn't find any matching answer. I'm a complete newbie to WPF, so please point me any errors I made.</p>
  
  <p>At first I have the following in my App.xaml.cs:</p>
  
  <pre><code>namespace WpfVideowand
  {
    public partial class App : Application
    {
      ...
      private void Application_Startup(object sender, StartupEventArgs e)
      {
        foreach (System.Windows.Forms.Screen MyScreen in System.Windows.Forms.Screen.AllScreens)
        {
          List&lt;string&gt; MyStrings = Xml.GetScreens(i);
          if (MyStrings[1] == "true")
          {
            OpenWindow(MyScreen, MyStrings[0], i);
          }
          i++;
          Shelf MyShelf = new Shelf(MyScreen, i, MyStrings[0]);
          MyShelf.Show();
        }
      }
      private void OpenWindow(System.Windows.Forms.Screen myScreen, string configName, int screenNumber)
      {
        Shelf NewShelf = new Shelf(myScreen, screenNumber, configName);
      }
    }
  }
  </code></pre>
  
  <p>And inside the Shelf.xaml.cs it looks this way:</p>
  
  <pre><code>namespace WpfVideowand
  {
    public partial class Shelf : Window
    {
      [DllImport("user32.dll")]
      static extern IntPtr GetActiveWindow();
      System.Windows.Forms.Screen _Screen { get; set; }
      ...
      public Shelf(System.Windows.Forms.Screen myScreen, int screenNumber, string configName)
      {
        InitializeComponent();
        _Screen = myScreen;
        ShowOnMonitor(screenNumber);
        ...
      }
      private void ShowOnMonitor(int screenNumber)
      {
        System.Windows.Forms.Screen[] ScreenArray;
        ScreenArray = System.Windows.Forms.Screen.AllScreens;
        int XCoord = Convert.ToInt32(ScreenArray[screenNumber].Bounds.Left);
        this.Left = XCoord;
        int YCoord = Convert.ToInt32(ScreenArray[screenNumber].Bounds.Top);
        this.Top = XCoord;
        IntPtr active = GetActiveWindow();
        System.Windows.Application.Current.Windows.OfType&lt;Window&gt;().SingleOrDefault(window =&gt; new WindowInteropHelper(window).Handle == active).Name = "Monitor" + screenNumber.ToString();
        System.Windows.Application.Current.Windows.OfType&lt;Window&gt;().SingleOrDefault(window =&gt; new WindowInteropHelper(window).Handle == active).WindowState = WindowState.Maximized;
      }
      ...
    }
  }
  </code></pre>
  
  <p>The way described above worked fine in Windows Forms Application. In WPF I have the problem, that I get the error message, that rectangle (the window) would have no Top or Left property.</p>
  
  <p>I even tried it in some other ways, like creating with </p>
  
  <pre><code>System.Windows.Forms.Screen _screen = System.Windows.Forms.Screen.FromControl(this);
  </code></pre>
  
  <p>an object, that would have .Top and .Left. But there I get the message, that I cannot convert a Shelf-object into a System.Windows.Forms.Control.
  Anyone a suggestion, how I could make my Screens appear on the monitor where it should be?</p>