preprocessor to detect IDE at design time. Follow
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.
Please sign in to leave a comment.
You should try `Design.IsDesignMode`: https://github.com/AvaloniaUI/Avalonia/blob/7842883961d094e08e9def7f30cf32fd573179c7/src/Avalonia.Controls/Design.cs#L9
This property should be set by the previewer process if your code is executing in the preview mode.
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: