Reputation: 3219
I have a constructor for my ViewModel given like so:
[ImportingConstructor]
public MyViewModel(IMyViewModel view)
: base(view)
{
if (tester.TestConnection(port, ref _errorMessages))
{
MethodThatBeginsAsync();
}
else
{
MessageBox.Show("Could not connect: " + _errorMessages);
_abortCommand.Execute(null);
}
}
I get an error message of CompositionException when trying to close the corresponding window if the check fails; how can I close the window before it opens?
I.e. the equivalent of:
_dialogResult = false;
ViewCore.close();
Upvotes: 0
Views: 1027
Reputation: 44096
"how can I close the window before it opens?"
Don't open it.
You don't have enough context here to provide a better answer than that. What window are you trying to close? What's the message box's parent window? What line throws a CompositionException?
(Note that displaying a messagebox directly from a ViewModel is already a pretty questionable practice, akin (imo) to displaying message boxes from a library that displays no other UI.)
Upvotes: 1