2010-06-24 5 views
0

나는 Composite Application Library (Prism)로 작업하려고 노력해 왔으며 Microsoft의 자습서를 따랐던 예쁜 표준 패턴을 설정했습니다. 기본적으로보기는 지역에 주입됩니다. 뷰는 동적으로 구축되어 프로그래밍 방식으로 컨트롤 등을 추가합니다.Silverlight에서 PRISM 패턴을 사용하는 ReBind 컨트롤

나는 해고 된 명령을 가지고 있으며 다시 포스트 백하면 모든 컨트롤을 완전히 다시 렌더링하는 대신 현재 뷰의 컨트롤을 리바 인하고 싶습니다.

그래서 나는 컨트롤의 리바 인딩을 강제하는 업데이트 된 버전으로 모델을 업데이트하려고했습니다. 그건 작동하지 않습니다. 내가 취해야 할 접근법을 잘 모르겠다. 프리즘에 익숙하지 않기 때문에 ...

아이디어가 있으신가요?

포스트 백

IEventAggregator aggregator = this.Container.Resolve<IEventAggregator>(); 
aggregator.GetEvent<DataInstanceLoadedEvent>().Subscribe(this.OnDataInstanceUpdated); 

I Microsoft에서 제안 된 패턴에 따라 바인딩하는 방법을 알아 낸 경우

public void OnDataInstanceUpdated(DataInstance updatedInstance) 
{ 
    if(this.View.Model != null){ 
     // We need to rebind here 
     IRegion region = this.LocateRegion(this.View); // gets the region.... 
     this.View.Model.CurrentDataInstance = updatedInstance; // update the model instance 
    } 
    else{ 
     // Render all controls over again since view.model is null ... 
    } 
} 

답변

0

의 구현을 처리하기 위해 이벤트를 구독합니다.

기본적으로 내 모델에서 INotifyPropertyChanged을 (를) 상속 받았다.

이 패턴을 따르면 모델 업데이트가 끝나면 실제로 속성이 변경되었음을 클라이언트에 알리는 이벤트를 발생시켜 모든 컨트롤을 리 바인드해야합니다.

public class MyModel : INotifyPropertyChanged 
{ 
    private DataInstance currentDataInstance; 
    public event PropertyChangedEventHandler PropertyChanged; 
    public DataInstance CurrentDataInstance 
    { 
     get 
     { 
      return this.currentDataInstance; 
     } 
     set 
     { 
      if (this.currentDataInstance == value) 
       return; 
      this.currentDataInstance = value; 
      this.OnPropertyChanged(new PropertyChangedEventArgs("CurrentDataInstance")); 
     } 
    } 
    protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) 
    { 
     if (this.PropertyChanged != null) 
      this.PropertyChanged(this, e); 
    } 
} 
관련 문제