我在應用MVVM模式。我有一個按鈕,點擊後,在我的ViewModel中調用委託命令。在該委託方法的一開始,我設置了一個屬性值(WaitOn),通過顯示一個動畫控件來通知用戶返回到UI中等待。爲什麼綁定刷新延遲直到完成委託命令? (MVVM)
但是,綁定顯示動畫控件不會刷新,直到委託完成執行,此時等待完成。爲什麼會發生這種情況,我該如何解決這個問題?
樣品XAML:從視圖模型
<Button Command="{Binding DoStuffCommand}" />
<ctl:MyAnimatedControl Name="ctlWait" Caption="Please Wait..."
Visibility="{Binding WaitNotification}" />
摘錄:
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();
}
很高興你能工作。只是想知道如果劇組轉換爲「動作」是絕對必要的,我敢肯定,lambda語法已經爲你照顧到了...... – Rory 2010-02-26 07:42:51