I'm applying the MVVM pattern. I've got a button which, when clicked, invokes a delegate Command in my ViewModel. At the very start of that delegate method, I set a property value (WaitOn) that should notify the user back in the UI to wait by displaying an animated control.
However, the binding to display that animated control doesn't get refreshed until the delegate has completed execution, by which point the waiting is done. Why does this happen and what should I do to workaround it?
Sample XAML:
<Button Command="{Binding DoStuffCommand}" />
<ctl:MyAnimatedControl Name="ctlWait" Caption="Please Wait..."
Visibility="{Binding WaitNotification}" />
Snippets from ViewModel:
public bool WaitPart1On
{
get { return _waitPart1On; }
set
{
_waitPart1On = value;
if (_waitPart1On == true)
{
WaitNotification = "Visible";
}
else
{
WaitNotification = "Hidden";
}
RaisePropertyChanged("WaitPart1On");
}
}
public string WaitNotification
{
get { return _waitNotification; }
set
{
_waitNotification = value;
RaisePropertyChanged("WaitNotification");
}
}
public void DoStuff()
{
WaitPart1On = true;
//Do lots of stuff (really, this is PART 1)
//Notify the UI in the calling application that we're finished PART 1
if (OnFinishedPart1 != null)
{
OnFinishedPart1(this, new ThingEventArgs(NewThing, args));
}
WaitPart1On = false;
}
And now code-behind from the XAML to catch the raised event:
public void Part1FinishedEventHandler(NewThing newThing, ThingEventArgs e)
{
//at this point I expected the WaitPart1On to be set to false
//I planned to put a new wait message up (WaitPart2)
FinishPart2();
}