I'm using a ListBox control with an ItemTemplate like so:
<ListBox Name="lbItemsList" ItemsSource="{Binding}" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ID}" Padding="5,0,0,0" />
<TextBlock Text=" - " Padding="5,0,0,0" />
<TextBlock Text="{Binding Description}" Padding="5,0,0,0" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Then, in the code I dynamically bind a collection to the ListBox like so:
lbItemssList.ItemsSource = _itemsList.Values;
But at times I need to rebind a different or modified list of items to the ListBox. When I do this, the ListBox doesn't update with the new list and it seems that the binding doesn't work correctly, unless I do this:
lbItemssList.ItemsSource = null;
lbItemssList.ItemsSource = _itemsList.Values;
I've done the same thing with other ListBox controls and not had this problem. What am I missing here?