0

I am trying to show another WPF window in my project, but it keeps giving me an error CS1061 (missing using directive). My code is representated below.

My project consists of two pages, one main, and one window that should open after the click.

The code of the click is where I get the error. It gives the error code showed before...

the click:

 } private void Win_Click(object sender, RoutedEventArgs e) { var form = new Window(); form.ShowDialog(); //ERROR CS1061 } 

I am using following Using-Directives:

using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Xml; using System.Xml.Linq; using System.Windows.Navigation; using System.Linq; using System.Text; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Windows.Forms; 

I also tried changing my click code to this, but I still get the same error:

 } private void Win_Click(object sender, RoutedEventArgs e) { var form = new Window(); form.Show(); //ERROR CS1061 } 

I hope you can help me finding the issue with my code snippet, why I keep getting that error. Thanks for taking your time to help me!

17
  • 2
    Visual Studio usually suggests what dependency to add. Have you tried clicking the little yellow lightbulb on the left when you're on that line? Or hitting "Ctrl+."? Commented Jan 25, 2019 at 14:31
  • 1
    @TimB I don't think try/catch will help, since this should be a compile time error. Commented Jan 25, 2019 at 14:38
  • 1
    Can you give the full text of your compiler error message - the documentation says Error CS1061 is "This error occurs when you try to call a method or access a class member that does not exist" Commented Jan 25, 2019 at 14:46
  • 1
    Your new window should be a specific window such as window1 or whatever rather than the generic base class. Commented Jan 25, 2019 at 14:55
  • 1
    Did you really create a window and decide to call it Window? That would be a bad idea. Commented Jan 25, 2019 at 15:46

1 Answer 1

2

I would suggest creating a named WPF window, creating an instance of that window (instead of a generic window), then running that code after replacing the window with the named wpf window.

Edit: I would also set the owner of your new named WPF window according to what object "owns" it.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for setting the owner. If you every have to write UI automation against a application that only sporadically sets the owner you will understand how frustrating this is.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.