I have a datagrid bound to a CollectionViewSource:
<Window.Resources>
<CollectionViewSource x:Key="vs"></CollectionViewSource>
</Window.Resources>
<DataGrid x:Name="dg" ItemsSource="{Binding Source={StaticResource vs}}" AutoGenerateColumns="true"/>
I populate the CollectionViewSource.Source using entity framework:
Private vsAs CollectionViewSource
vs = CType(FindResource("vs"), CollectionViewSource)
dim db as new dbcontext
vs.Source = db.SomeEntities.ToList
I want this data to refresh itself from the database every so often, at the moment I have it on a timer like so:
Me.Dispatcher.Invoke(Sub()
dim db as new dbcontext
vs.Source = db.SomeEntities.ToList
End Sub)
End Sub
However this causes any sorting from the datagrid, along with any selected items to be lost, it also causes a noticable delay on screen.
What is the correct way to update a collectionviewsource from a database using entity framework?
Thanks