2012-11-28 2 views
3

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의 다른 모든 요소는 올바르게 작동합니다. 내 버튼이 올바르게 활성화/비활성화됩니다. 내 그리드가 멋지게 업데이트되는 등

+0

콜백의 ViewModel 코드를 게시 할 수 있습니까? –

+0

BusyIndicator 컨트롤이 문제가되면 항상 자신의 컨트롤을 만들 수 있습니다. Busy 표시기와 View 내용을 행없이 표 형태로 배치하고 표시기의 가시성을 Busy 속성에 바인딩하면됩니다. –

+0

BusyIndicator가 아니라 비동기 스레드 문제 일 수 있다고 생각합니다. 어쩌면 WPF의 시각적 스레드가있을 수 있습니다. 어쩌면'IsBusy' 속성을 false로 다시 설정하기 위해'SynchronizationContext'를 사용하여 해결할 수도 있습니다. –

답변

0

나는 그것을 풀 었다고 생각한다. 위의 예제 코드를 게시하여 (모든 테스트 혼란을 제거하고) 나는 그것을 풀었다.

괜찮습니다. 모델이 작동하지만 웹 서비스에 대해 말하고 있기 때문에 첫 번째 호출 이후에 내 webservice 호출이 너무 빨라서 bsy infdicator를보기에는 너무 빠르 게되었습니다.

그래서 ... 나는 게으르며 잠을 잤습니다. 하지만 콜백에 잠을 자고. 콜백은 UI 스레드에서 시작 되었기 때문에 잘못된 지점에서 블로킹합니다. 바쁜 표시기가 이미 와서 잠을 잤을 때가왔다.

그래서 DoWork 메소드 (ui threqad 외부에 있음)로 이동하고 사용중 표시기 sstays로 이동합니다.

어리석은 나를. 덕분에 조언 휄로우들!