DependencyProperty
コレクション( )であるプロパティを持つエンティティを保持するこれがありますShoutBox.Entities
:
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<ShoutBoxEntry>