검색 확장이 포함 된 사용자 지정 WPF 컨트롤을 작성했습니다. 이름을 MyControl
으로 지정합시다. 컨트롤은 ItemsControl
클래스의 자손입니다.WPF CollectionViewSource 다중 뷰?
는 그래서 이런 식으로 데이터 소스를 공급 : 는
제어 자체는 소스 컬렉션의보기를 필터링
protected override void OnItemsSourceChanged(System.Collections.IEnumerable oldValue, System.Collections.IEnumerable newValue)
{
if (newValue != null)
{
ICollectionView view = CollectionViewSource.GetDefaultView(newValue);
view.Filter += this.FilterPredicate;
}
if (oldValue != null)
{
ICollectionView view = CollectionViewSource.GetDefaultView(oldValue);
view.Filter -= this.FilterPredicate;
}
base.OnItemsSourceChanged(oldValue, newValue);
}
사용 (따라서 내측리스트 박스를 표시).
이제 우리는 동일한 DynamicSource를 사용하여 XAML에 정의 된 MyControls가 10 개 있다고 가정합니다. 그 중 하나가 소스 컬렉션에 필터를 적용하면 다른 모든 인스턴스에도 영향을 미칩니다.
이 동작을 피하기 위해 컨트롤을 어떻게 변경 하시겠습니까?
대단히 좋습니다. 정말 고맙습니다. 대단히 감사합니다! 그냥 noobie 질문입니다 - RegisterReadOnly()는 '읽기 전용'이라고 말하면 무슨 뜻입니까? –
ItemsSourceView에서 ItemsSourceView = new CollectionViewSource {Source = newValue} .View를 설정했기 때문에 ItemsSourceView가 DP 인 경우 Setter를 단순히 삭제할 수 없기 때문에 ItemsSourceChanged에서 묻습니다. –
예. 그것은 단지 초기화를 변경하는 것 이상의 것입니다 : private static 읽기 전용 DependencyPropertyKey MyDPPropertyKey = DependencyProperty.RegisterReadOnly (...); public static readonly DependencyProperty MyDPProperty = MyDPPropertyKey입니다.DependencyProperty; 공용 개체 MyDP { \t get {return (object) GetValue (MyDPProperty); } \t 개인 집합 {SetValue (MyDPPropertyKey, value); } } –