绑定集合SubProperty更新

时间:2013-02-09 15:12:28

标签: wpf properties observablecollection

我在更新Listview的值时遇到问题,这会导致绑定ObservableCollection Sub属性,

My Principal ViewModel

public class ClienteViewModel : ViewModelBase
    {
...
    public ContatoViewModel ContatoViewModel
    {
      get
      {
         contatoViewModel = new ContatoViewModel(db,ClienteSelecionado);
         return contatoViewModel;
      }
      set
      {
         this.contatoViewModel = value;
         RaisePropertyChanged("ContatoViewModel");
      }
   }
}

Secundary ViewModel

 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 Main函数中。我该怎么做才能使它适用于子属性?

0 个答案:

没有答案