I have this DependencyProperty
which holds an entity with a property that is a collection (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); }
}
It is being binded in xaml
like such:
<ItemsControl ItemsSource="{Binding ShoutBox.Entries}">
.
.
</ItemsControl>
When I bind it the first time, it works as expected but there are times when I need to add items to the collection (with a method that is in the same control), like such:
public void AddNewEntry(ShoutBoxEntry newEntry)
{
Dispatcher.Invoke(new Action(() =>{
ShoutBox.Entries.Add(newEntry); //Adding directly the the Dependency property
}));
}
The problem is that when I add a new element with the above method, the item isn't being displayed in the ItemsControl
.
My question is, why isn't the new element that I am adding isn't being displayed in the ItemsControl
?
[Edit]
Entries
(ShoutBox.Entries) is of type List<ShoutBoxEntry>