title: open wpf from winform throws object reference not set to an instance of
body: <p>I have a WPF custom control and I needs to open it from WinForm. I have followed all steps mentioned in <a href="http://weblogs.asp.net/jdanforth/open-a-wpf-window-from-winforms" rel="nofollow noreferrer">http://weblogs.asp.net/jdanforth/open-a-wpf-window-from-winforms</a> and <a href="https://stackoverflow.com/questions/8311956/open-wpf-window-in-windowsform-app">Open WPF window in WindowsForm APP</a></p>
  
  <p>But still it gives me an object reference not set to an instance of exceptions.</p>
  
  <p>Winform:</p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
          {
              var notificatioinapp = new WpfCustomControlLibrary1.Window1();
              ElementHost.EnableModelessKeyboardInterop(notificatioinapp);
              notificatioinapp.Show();
          }
  </code></pre>
  
  <p>WPF custom control:</p>
  
  <pre><code>public partial class Window1 : Window
      {
          public Window1() : base()
          {
              InitializeComponent();
              this.Closed += this.NotificationWindowClosed;
          }
      public new void Show()
      {
          this.Topmost = true;
          base.Show();
  
          this.Owner = System.Windows.Application.Current.MainWindow;
          this.Closed += this.NotificationWindowClosed;
          var workingArea = Screen.PrimaryScreen.WorkingArea;
  
          this.Left = workingArea.Right - this.ActualWidth;
          double top = workingArea.Bottom - this.ActualHeight;
  
          foreach (Window window in System.Windows.Application.Current.Windows)
          {
              string windowName = window.GetType().Name;
  
              if (windowName.Equals("NotificationWindow") &amp;&amp; window != this)
              {
                  window.Topmost = true;
                  top = window.Top - window.ActualHeight;
              }
          }
  
          this.Top = top;
      }
      private void ImageMouseUp(object sender,
          System.Windows.Input.MouseButtonEventArgs e)
      {
          this.Close();
      }
  
      private void DoubleAnimationCompleted(object sender, EventArgs e)
      {
          if (!this.IsMouseOver)
          {
              this.Close();
          }
      }
  
      private void NotificationWindowClosed(object sender, EventArgs e)
      {
          foreach (Window window in System.Windows.Application.Current.Windows)
          {
              string windowName = window.GetType().Name;
  
              if (windowName.Equals("NotificationWindow") &amp;&amp; window != this)
              {
                  // Adjust any windows that were above this one to drop down
                  if (window.Top &lt; this.Top)
                  {
                      window.Top = window.Top + this.ActualHeight;
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Appreciate any support.</p>