0

I have a WPF application which opens a popup when the main window is loaded. The problem is when I select the .xaml file in the solution explorer in Visual Studio 2013, the popup "pops" even when the application is not running. I suppose it is an intended behavior since the visualizer needs to execute the code in order to render the page layout, but for now I need to close it every time I load the page... I cannot temporarily disable this popup since it has some start logic for the application (selection of a location,...).

Here is the code of the popup trigger

public GeneralProcess() //usercontrol
{
    InitializeComponent();
    Loaded += GeneralProcess_Loaded;
}

void GeneralProcess_Loaded(object sender, RoutedEventArgs e)
{
    var popup = new StationSelect();
    popup.Owner = Window.GetWindow(this);
    popup.ShowDialog();
}

Is there a way to know if the application is running or if I am in the visualizer, or is there a way to disable the Loadedevent just for visual studio ? The goal is to still be able to see the page for easy editing.

EDIT : this question is a duplicate. However this answer worked for me.

Goufalite
  • 2,253
  • 3
  • 17
  • 29
  • Possible duplicate of [How to tell if .NET code is being run by Visual Studio designer](https://stackoverflow.com/questions/73515/how-to-tell-if-net-code-is-being-run-by-visual-studio-designer) – Goufalite Aug 24 '17 at 12:10

1 Answers1

2
void GeneralProcess_Loaded(object sender, RoutedEventArgs e)
{
    if (DesignerProperties.GetIsInDesignMode(this))
        return;
    var popup = new StationSelect();
    popup.Owner = Window.GetWindow(this);
    popup.ShowDialog();
}
Isma
  • 14,604
  • 5
  • 37
  • 51
  • Doesn't work : `IsInDesignTool` is not defined. I'm in .NET 4.5. But nice approach, I'll search more on this DesignerProperties. – Goufalite Aug 24 '17 at 10:48
  • 1
    Thank you! For those who come here be sure to rebuild the project and reopen the .xaml files after doing this. – Goufalite Aug 24 '17 at 12:13