나는이 콜렉션 (ShoutBox.Entities
) 인 특성을 가진 개체를 보유하고이 DependencyProperty
:WPF : 데이터 바인딩 컬렉션에 요소를 추가 (A 종속성 속성)
public static readonly DependencyProperty ShoutBoxProperty = DependencyProperty.Register("ShoutBox",typeof (ShoutBox),typeof (ShoutBoxViewerControl));
public ShoutBox ShoutBox
{
get { return (ShoutBox) GetValue(ShoutBoxProperty); }
set { SetValue(ShoutBoxProperty, value); }
}
그것은 같은 xaml
에 바인더 제본되고있다 같은 :
<ItemsControl ItemsSource="{Binding ShoutBox.Entries}">
.
.
</ItemsControl>
내가 처음을 결합하면 예상대로 작동하지만이 같은처럼 (같은 제어하는 방법) 컬렉션에 항목을 추가 할 때 거기에 시간 :
public void AddNewEntry(ShoutBoxEntry newEntry)
{
Dispatcher.Invoke(new Action(() =>{
ShoutBox.Entries.Add(newEntry); //Adding directly the the Dependency property
}));
}
위의 방법으로 새 요소를 추가 할 때 항목이 ItemsControl
에 표시되지 않는 것이 문제입니다.
내 질문은 왜이 ItemsControl
에 표시되지 않는 추가하고 새로운 요소는 아니다, 입니까?
[편집]
Entries
(ShoutBox.Entries)이
목록 –
합니다. List를 ObservableCollection 로 변경하면 제대로 작동합니다. http://msdn.microsoft.com/en-us/library/ms668604.aspx –
NotDan
항목 추가 및 제거를 선택하려면 컬렉션에서 INotifyPropertyChanged가 아닌 ICollectionChanged를 구현해야합니다. –