preprocessor to detect IDE at design time.

Okay, here is a good one. I'm trying to open a serial port in a (Avalonia) window's constructor. The issue is that the (Rider) IDE creates the GUI in the editor and opens the serial port. Then when the application runs it cannot open the serial port because its open in the editor. If I build and run the program outside of the IDE it works fine. My question is if there is a preprocessor directive to directive if the GUI is being rendered in the IDE and if so how to use it.
Comment actions Permalink


You should try `Design.IsDesignMode`:

This property should be set by the previewer process if your code is executing in the preview mode.

Comment actions Permalink

I was able to accomplish what I desired using this method thanks to some help from the Avalonia Gitter chat.  I added this to my form:




Then this was added to the view model for the form:


if (!Design.IsDesignMode)



Please sign in to leave a comment.