MVVMパターンを適用しています。クリックすると、ViewModelでデリゲートコマンドを呼び出すボタンがあります。そのデリゲートメソッドの最初に、アニメーション化されたコントロールを表示して待機するようにUIにユーザーに通知するプロパティ値(WaitOn)を設定しました。
ただし、そのアニメーション化されたコントロールを表示するためのバインディングは、デリゲートが実行を完了するまで更新されません。実行が完了すると、待機が完了します。なぜこれが発生し、それを回避するにはどうすればよいですか?
サンプルXAML:
<Button Command="{Binding DoStuffCommand}" />
<ctl:MyAnimatedControl Name="ctlWait" Caption="Please Wait..."
Visibility="{Binding WaitNotification}" />
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;
}
そして今、発生したイベントをキャッチするためにXAMLからコードビハインドします。
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();
}