BusyIndicator가 있는데, 이는 내 뷰 모델에서 Busy 속성에 IsBusy를 바인딩합니다.wpf 확장 툴킷 BusyIndicator 속성에 대한 바인딩
<xctk:BusyIndicator IsBusy="{Binding Busy}" x:Name="busyBox" Grid.Row="2"
HorizontalAlignment="Center"
VerticalAlignment="Center" BusyContent="Contacting Server" >
</xctk:BusyIndicator>
웹 서비스 호출 (asynch)을 시작하고 콜백에서 false로 설정하면 busy가 true로 바뀝니다.
위의 경우 처음 사용하면 좋지만, 매번 사용 중이면 표시기가 더 이상 표시되지 않습니다. 콜백에 thread.sleep을 추가했습니다. (x = case에서는 2 번째로 너무 빠르게 움직였습니다).
다른 바인딩 된 컨트롤과 예상대로 작동하기 때문에 내 속성이 올바르게 알리는 것으로 알고 있습니다. 단지 busyindicator가 (BTW 내가 사용하고 MVVM 라이트 툴킷 V3)
VIEW 모델 코드가
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
}
이것은 웹 서비스 안타 클래스가
하나 개의 사용을 위해 좋은 것 같다
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의 다른 모든 요소는 올바르게 작동합니다. 내 버튼이 올바르게 활성화/비활성화됩니다. 내 그리드가 멋지게 업데이트되는 등
콜백의 ViewModel 코드를 게시 할 수 있습니까? –
BusyIndicator 컨트롤이 문제가되면 항상 자신의 컨트롤을 만들 수 있습니다. Busy 표시기와 View 내용을 행없이 표 형태로 배치하고 표시기의 가시성을 Busy 속성에 바인딩하면됩니다. –
BusyIndicator가 아니라 비동기 스레드 문제 일 수 있다고 생각합니다. 어쩌면 WPF의 시각적 스레드가있을 수 있습니다. 어쩌면'IsBusy' 속성을 false로 다시 설정하기 위해'SynchronizationContext'를 사용하여 해결할 수도 있습니다. –