I've a problem in my application Client/Server. I work with the MVVM pattern. In my view, I've a DataGrid
which is bound with a ICollection
in my ViewModel with these lines of code :
public ICollectionView Customers
{
get
{
return _customers;
}
set
{
_customers= value;
RaisePropertyChanged("Customers");
}
}
_customers = CollectionViewSource.GetDefaultView(Manager.Instance.Customers());
_customers .SortDescriptions.Add(new SortDescription("CreationDate", ListSortDirection.Descending));
At the start, these two lines work fine : my DataGrid
has my list of customers and the sort is ok.
But when the server update my list of customer, i would like to Update my collection and, so, my DataGrid
.
So, I received a notification with my new List of customers. When I received this notification, I update my collection with these lines :
Customers = CollectionViewSource.GetDefaultView(e.CustomersInfo);
_customers.SortDescriptions.Clear();
_customers .SortDescriptions.Add(new SortDescription("CreationDate", ListSortDirection.Descending));
Customers.Refresh();
Here, my DataGrid
is well refresh with the good data, but the sort is not refresh beacause, at the beginning, my list of customers is sorted by the CreationDate, but after the refresh, my list is sorted by CustomersName.
Here, my XAML code :
<DataGrid AutoGenerateColumns="false" ItemsSource="{Binding Customers, Mode=TwoWay}" IsSynchronizedWithCurrentItem="True" Name="dtgEventInfo" SelectedItem="{Binding SelectedCustomers, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ItemContainerStyle="{StaticResource ItemContStyle}" IsEnabled="True" IsReadOnly="True" Margin="0,0,330,0" GridLinesVisibility="None" SelectionMode="Single">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name, Mode=TwoWay}" Header="Name" MinWidth="40" Width="Auto"/>
<DataGridTextColumn Binding="{Binding CreationDate, Mode=TwoWay}" Header="Date" MinWidth="50" Width="Auto"/>
</DataGrid.Columns>
</DataGrid>
Do you have any ideas to help me please ? After some researches, I've bot found any solutions...