我在更新使绑定 ObservableCollection 子属性的 Listview 的值时遇到问题,
我的主要视图模型
public class ClienteViewModel : ViewModelBase
{
...
public ContatoViewModel ContatoViewModel
{
get
{
contatoViewModel = new ContatoViewModel(db,ClienteSelecionado);
return contatoViewModel;
}
set
{
this.contatoViewModel = value;
RaisePropertyChanged("ContatoViewModel");
}
}
}
辅助视图模型
public class ContatoViewModel : ViewModelBase
{
public ObservableCollection<Contato> Contatos{
// list values
}
public ICommand addContato{get;set;}
public ICommand removeContato{get;set;}
public Contato SelectedContato{get;set;}
}
}
XAML:
<ListView ItemsSource="{Binding ContatoViewModel.Contatos},UpdateSourceTrigger=PropertyChanged">
或者
<ListView DataContext="{Binding ContatoViewModel}" ItemsSource="{Binding Contatos,UpdateSourceTrigger=PropertyChanged}" >
或者
<Grid DataContext="{Binding ContatoViewModel}">
<ListView ItemsSource="{Binding Contatos,UpdateSourceTrigger=PropertyChanged}" >
</Grid>
值显示正常,但是当我插入一些值并调用 raisePropertyChanged ObservableCollection() 时,什么也没更新。
但是如果列表在 ViewModel 中,主要功能正常。我应该怎么做才能使其与子属性一起使用?