WPF组合框ItemSource在删除后没有更新
本文关键字:更新 删除 组合 ItemSource WPF | 更新日期: 2023-09-27 18:04:37
我在更新组合框时遇到问题。我已经实现了INotifyPropertyChanged。一切都很好,它是绑定的。这是我的Combobox:
<ComboBox Grid.Column="1" Grid.Row="0"
ItemsSource="{Binding Path=Documents, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True,Mode=TwoWay}"
DisplayMemberPath="BrDokumentaDatum"
SelectedValuePath="IdDokumenta"
SelectedItem="{Binding Path=CurrentDocument, UpdateSourceTrigger=PropertyChanged}"
IsSynchronizedWithCurrentItem="True"
SelectedIndex="0">
</ComboBox>
这是我的ViewModel:
private ObservableCollection<Dokument> documents;
public ObservableCollection<Dokument> Documents
{
get
{
return this.documents;
}
set
{
this.documents = value;
OnPropertyChanged("Documents");
}
}
我有一个命令它被绑定到我的按钮
public ICommand DeleteDocumentCommand
{
get
{
if (this.deleteDocumentCommand == null)
{
this.deleteDocumentCommand = new CommandBase(i => this.DeleteDocument(), null);
}
return this.deleteDocumentCommand;
}
}
DeleteDocument()调用服务:
private void DeleteDocument()
{
if (confirm("Želite li obrisati odabrani dokument", "Obriši dokment"))
{
bool deleted = serviceClient.DeleteDocument(this.CurrentDocument.IdDokumenta);
}
}
我的文档已被删除。我的组合框没有使用新项目源更新。有什么问题吗?
我没有看到任何从Documents
ObservableCollection中删除Dokument
的代码。
您可以将其从底层数据存储库中删除,但Documents
属性与此完全断开连接,并且仍将保留数据实体的副本。