John the Ripper
John the Ripper

Reputation: 2439

Messagebox.show fires twice after button click (MVVM)

I am using Galasoft MVVMLight. I have a button bound to a command which sends a message to the view to display a messagebox asking for confirmation. If I click either the Yes or No on the messagebox it performs the necessary actions then shows up again. However if I step through the program instead I only get the messagebox once. Is this a bug or is something else going on?

EDIT: I modified the messagebox.show line by adding an Icon and default result and now I can't reproduce this behavior... I'm stumped... if it happens again I'll try a counter like airplaneman19 suggested.

Upvotes: 0

Views: 491

Answers (2)

Denis Biondic
Denis Biondic

Reputation: 8201

I had a similar problem once, I mean, with MessageBox firing twice. It was due to focus changes, and ListView in WinForms fired another selection changed event when running the app; but when debugging - some focus change was missing, and there was no bug :)

I hope this atleast gives you some ideas...

Upvotes: 0

airplaneman19
airplaneman19

Reputation: 1159

Try tracking the amount of times the MessageBox shows up with an integer, like so:

int counter = 0;
if(counter == 0){
  MessageBox.Show();
  counter++;
}
else if (counter == 1)
  /*Do something that won't alter the program just to escape the if....else statement
    like "x++";

Upvotes: 1

Related Questions