我在应用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