I encountered a strange problem with Visual Studio 2022 and its XAML designer. My program is started with command line arguments, and if the proper amount of arguments is not entered, the program shall terminate:
string[] args = System.Environment.GetCommandLineArgs();
if (args.Length != 2)
{
MessageBox.Show("Wrong number of command line arguments!");
Application.Current.Shutdown();
}
This works fine when executing the code, but the XAML designer of the MainWindow will not load anymore. I use Blend to create the design:
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d:DataContext="{d:DesignInstance Type=local:MyViewModel, IsDesignTimeCreatable=True}
Instead of loading the designer, the message box with the error "Wrong number of command line arguments!" is shown, which probably means that the command line arguments I defined in the debug properties of the project are not used for the creation of the design preview.
Is there a way to solve this problem?