私はむしろ面白い問題があります。私はのように見えることWPFのデータグリッドを持っている:私はCRUD操作を行っており、そのグリッド内のデータにWPFでICollectionViewを使ってDataGridを更新するMVVM
<DataGrid ItemsSource="{Binding View, IsAsync=True, Mode = TwoWay}"
AutoGenerateColumns="False"
EnableColumnVirtualization="True"
EnableRowVirtualization="True"
VirtualizingStackPanel.VirtualizationMode="Standard"
VirtualizingStackPanel.IsVirtualizing="True">
COLLUMNS
</DataGrid>
、私が操作を追加または削除した後に表示を更新することができないようで、私はレコードやフィルタを更新したときにそれが完璧に動作しますそれ。私は、ビューモデルにしようとした
単純なC#のOPS: 読む:
public CommendationViewModel()
{
this._catalog = new CatalogContexct();
this._commendations = this._catalog.Commendations.ToList();
var commendation = new ListCollectionView(this._commendations);
this.CommendationView = CollectionViewSource.GetDefaultView(commendation);
this.AddCommand = new RelyCommand(AddEntity, param => this._canExecute);
this.EditCommand = new RelyCommand(EditEntity, param => this._canExecute);
this.UpdateCommand = new RelyCommand(UpdateEntity, param => this._canExecute);
this.RemoveCommand = new RelyCommand(RemoveEntity, param => this._canExecute);
this.NameCommand = new RelyCommand(Filter, param => this._canExecute);
this.CancelCommand = new RelyCommand(Cancel, param => this._canExecute);
}
そして追加:
public void AddEntity(object obj)
{
if(string.IsNullOrEmpty(this.Name))
{
MessageBox.Show("Brak nazwy do dodania");
return;
}
var commendation = new Commendation() { Name = this.Name };
this._catalog.Commendations.Add(commendation);
this._catalog.SaveChanges();
var commendationRefresh = new ListCollectionView(this._catalog.Commendations.ToList());
this.CommendationView = CollectionViewSource.GetDefaultView(commendationRefresh);
this.CommendationView.Refresh();
MessageBox.Show("Nowe źródło polecenia zostało dodane");
}
あなたは私がaddコマンドでビューを更新しようとしたが、それはうまくいきませんでした見たよう
。助言がありますか?
DataGridのItemsSourceプロパティを "View"というプロパティにバインドしましたが、 "Co"というプロパティをリフレッシュしていますmmendationView "と表示されます。 DataGridがバインドされているのと同じビューを更新する必要があります。 – mm8