アプリケーションのクライアント/サーバーに問題があります。私はMVVMパターンで作業しています。私の見解では、これらのコード行で ViewModel にバインドされている がありますDataGrid
。ICollection
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));
最初は、次の 2 行が正常に機能します。my DataGrid
has my list of customers and the sort is ok.
しかし、サーバーが私の顧客リストを更新するとき、私は自分のコレクションを更新したいと思いDataGrid
ます。それで、新しい顧客リストの通知を受け取りました。この通知を受け取ったとき、コレクションを次の行で更新します。
Customers = CollectionViewSource.GetDefaultView(e.CustomersInfo);
_customers.SortDescriptions.Clear();
_customers .SortDescriptions.Add(new SortDescription("CreationDate", ListSortDirection.Descending));
Customers.Refresh();
ここではDataGrid
、適切なデータで適切に更新されていますが、最初は顧客のリストが CreationDate で並べ替えられているため、並べ替えは更新されていませんが、更新後は CustomersName で並べ替えられています。
ここで、私の XAML コード:
<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>
私を助けてくれるアイデアはありますか?いくつかの調査の後、私はボットが解決策を見つけました...