我有一个 BusyIndicator,我将 IsBusy 绑定到我的视图模型中的 Busy 属性。
<xctk:BusyIndicator IsBusy="{Binding Busy}" x:Name="busyBox" Grid.Row="2"
HorizontalAlignment="Center"
VerticalAlignment="Center" BusyContent="Contacting Server" >
</xctk:BusyIndicator>
当我开始 web 服务调用(异步)时,我将忙切换为 true,并在回调中将其设置为 false。
这第一次效果很好,之后每次都不再显示忙碌指示符。我在回调中添加了一个 thread.sleep (只是在 x=case 它第二次移动得太快了)。
我知道我的属性正在正确通知,因为其他绑定控件并按预期工作。似乎busyindicator只适用于一种用途
(顺便说一句,我正在使用 mvvm light toolkit v3)
查看型号代码
this.Busy = true; //This proverty is declared correctly with notifications etc
IPersonSearchService searcher = new PersonSearchService(); //class that does my webservice, ad i pass it a callback method from my UI (see below)
searcher.FindByPersonDetails(ps, GetAllPeopleCallback);
private void GetAllPeopleCallback (PersonSearchResult result, Exception e)
{
this.Busy = false;
((Models.PersonSearch)this.Model).Persons = result.Persons; //bound to my grid
CommandManager.InvalidateRequerySuggested(); //i need to do this to make a button who's canexecute command binding happen
}
这是访问 web 服务的类
class PersonSearchService : IPersonSearchService
{
public void FindByPersonDetails(WSPersonSearch.PersonSearch ps, Action<PersonSearchResult, Exception> Callback)
{
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += delegate(object s, DoWorkEventArgs args)
{
WSPersonSearch.PersonSearch search = (WSPersonSearch.PersonSearch)args.Argument;
PersonSearchWebServiceClient wc = new PersonSearchWebServiceClient();
PersonSearchResult r = wc.FindByPersonDetails(ps);
args.Result = r;
};
worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
{
PersonSearchResult result = (PersonSearchResult)args.Result;
Callback(result, null);
};
worker.RunWorkerAsync();
}
}
ui 上的其他所有内容都表现得很好。我的按钮正确激活/停用。我的网格得到很好的更新等等