【发布时间】:2014-05-23 07:17:20
【问题描述】:
我在更新组合框时遇到问题。我已经实现了 INotifyPropertyChanged。一切都很好,它被绑定了。所以这是我的组合框:
<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);
}
}
我的文档已删除。我的组合框不会随新项目源更新。 有什么问题?
【问题讨论】:
-
您的 serviceClient.DeleteDocument 方法如何与视图模型上的现有 Documents ObservableCollection 交互?你真的要从这个集合中删除这个文档吗?
-
你在serviceClient.DeleteDocument方法中做了什么? - 请出示代码。