I am trying to set up a ListBox that gets it's data from a CollectionViewSource. What I want to happen is that when I update the underlying data source the ListBox also updates. My Xaml looks like this...
<Window.Resources>
<ObjectDataProvider x:Key="AppTests" ObjectType="{x:Type Application:AppTestProvider}" MethodName="GetAppTests" />
<CollectionViewSource x:Key="cvs" Source="{StaticResource AppTests}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Priority" Direction="Ascending" />
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</Window.Resources>
<Grid>
<ListBox x:Name="TestList" ItemsSource="{Binding Source={StaticResource cvs}}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding TestName}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
This displays the data fine but if I change the underlying data then the changes don't appear on the grid until I call the cvs.View.Refresh()
method in the code behind.
How can I make this "observable" so the changes happen automatically?
Note: The reason for using the CVS was to provide sorting to the list based on a property in the underlying objects.