none
Weird VS bug - Window opens automatically when designer loads for the first time

    Question

  • Hi,

    I have a WPF application with 2 windows. I started having this weird bug...the first time after I open VS, double clicking on the Window.XML will actually run the window right after loading the designer. This would happen only once after VS is opened and only with this window.

    Also, when I run without debug (Ctrl+F5), both my starting window and the second open (also, only for the first time). If i debug, this would not happen. I tried removing from my code the line that opens this window, and it still happens.

    It's like something in the XML tells it to open...

    ----

    I tried upgrading VS to 2015 (which is the same as uninstalling and installing, right?) still nothing.

    So I started removing everything from my code, clearing the window and deleting DataContext code...basically anything that has anything to do with that window. And guess what? The window keeps opening! And even after I deleted the entire content of the window, the window opens with all the buttons in it! What kind of weird bug is that?!

    Any ideas?

    EDIT: I literally deleted the entire content of the project, all files windows and classes, and the window still opens. I started a new project and copied the code, same thing. It's like there is a ghost or something...please help.

    Thanks in advance

    • Edited by Tomer Agmon Saturday, January 16, 2016 9:35 PM
    Saturday, January 16, 2016 8:25 PM

Answers

  • I found the solution.

    The problem was partially a bug and partially a mistake in my code.

    The window started because I had a line in the ViewModelLocator which was "Window.Show".

    The XAML of the window had a "get" function from ViewModelLocator as "DataContext". Each time the designer loaded, it would go to that code and run it.

    That I understood pretty quickly by myself. What confused me is that even after deleting that line, it would still happen. Either there is a "DataContext" cache i'm not aware of or it's just a bug.

    Anyways, creating a new solution and never putting that line there fixed the problem.

    • Marked as answer by Tomer Agmon Monday, January 18, 2016 6:32 PM
    Monday, January 18, 2016 6:32 PM

All replies

  • Hi Tomer Agmon,

    What do you mean the window will opened automatically? Do you mean the project will run automatically when you open Visual Studio? Please provide a small video or a gif image to help me understanding your problem?

    >>I started a new project and copied the code, same thing

    Please copy the code one by one to make sure whether it is caused by one line of these code. And you also can create a new WPF project with two windows without any content to make sure whether it is related to your code or Visual Studio.

    In addition, please check whether there has other third part software is running, when you operate your project.

    Best Regards,
    Weiwei

    Monday, January 18, 2016 6:27 AM
    Moderator
  • I found the solution.

    The problem was partially a bug and partially a mistake in my code.

    The window started because I had a line in the ViewModelLocator which was "Window.Show".

    The XAML of the window had a "get" function from ViewModelLocator as "DataContext". Each time the designer loaded, it would go to that code and run it.

    That I understood pretty quickly by myself. What confused me is that even after deleting that line, it would still happen. Either there is a "DataContext" cache i'm not aware of or it's just a bug.

    Anyways, creating a new solution and never putting that line there fixed the problem.

    • Marked as answer by Tomer Agmon Monday, January 18, 2016 6:32 PM
    Monday, January 18, 2016 6:32 PM