I have a ListBox which is bound to a collection. When I add an item to the collection I see no change in the ListBox.
However, when I resize the window a little, then the new item suddenly appears in the ListBox. So the binding seems to be working, just the refresh is missing.
What might I be doing wrong here?
XAML:
<ListBox Grid.Row="2" Grid.Column="1" Name="TestModules" ItemsSource="{Binding ModuleList}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding TE}"/>
<TextBlock Text="-"/>
<TextBlock Text="{Binding AF}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Code:
private List<PruefModule> _moduleList = new List<PruefModule>();
public ICollectionView ModuleList { get; private set; }
ModuleList = CollectionViewSource.GetDefaultView(_moduleList);
_moduleList.Add((PruefModule)ModulesGrid.SelectedItem);
You should use an ObservableCollection instead of the ICollectionView and it should work ok.
From MSDN: