2017-11-30 25 views
0

필자는 Name 뷰, Address 뷰, Country 뷰의 컬럼이있는 datatemplate의 텍스트 박스를 포함하고있다. 이제이 listview의 Itemsource는 내 viewmodel 클래스의 모델의 관찰 가능한 컬렉션에 바인딩됩니다.viewmodel에서 listview를 itemsource에 바인딩 된 모델 observable 컬렉션으로 업데이트하는 방법

VM의 일부 조건에서 이름과 주소를 비워서 ObjModel (유형이 ObservableCollection<Model> 인)을 업데이트하고 있으며 viewmodel 클래스의 ObjModel 객체에서 비어있는 값을 볼 수 있습니다. 하지만 그 변경 사항은 UI (ListView)에 반영되지 않습니다. 뭔가 빠졌는 지, 어떻게 목록보기를 업데이트 할 수 있습니까?

<DataTemplate x:Key="EquipmentItemTemplate"> 
       <Grid 
        x:Name="ListItem" 
        Height="40" 
        ZIndex="1"> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="200" /> 
         <ColumnDefinition Width="250" /> 
         <ColumnDefinition Width="250" /> 
        </Grid.ColumnDefinitions> 
        <TextBlock Grid.Column="0" Text="{Binding Path=Name}" /> 
        <TextBlock Grid.Column="1" Text="{Binding Path=Address}" /> 
        <TextBlock Grid.Column="2" Text="{Binding Path=Country}" /> 
       </Grid> 
      </DataTemplate> 
<ListView x:Name="MaintenanceElements" 
       ItemContainerStyle="{StaticResource SequenceListItemStyle}" 
       ItemTemplate="{StaticResource EquipmentItemTemplate}" 
       ItemsSource="{Binding EquipmentMaintenanceEntityItemsCollection}" 
       SelectedItem="{Binding SelectedMaintenanceElement}"> 
        <ListView.View> 
         <GridView AllowsColumnReorder="False"> 
          <GridViewColumn 
            Width="200" 
            local:GridViewSort.PropertyName="Name" 
            Header="Name" /> 
          <GridViewColumn 
            Width="250" 
            local:GridViewSort.PropertyName="Address" 
            Header="Address" /> 
          <GridViewColumn 
            Width="250" 
            local:GridViewSort.PropertyName="Country" 
            Header="Country" /> 

         </GridView> 
        </ListView.View>     
       </ListView> 

보기 모델이 포함되어 있습니다 :

public ObservableCollection<Model> ObjModel { get; set; } 

어떤 조건의 일부 어디

ObjModel[0].Name= string.Empty; 

그것은 ListView에 있기 때문에에 업데이트하지 않습니다

내보기는이 같은 것입니다 그것의 itemsource는 모델 객체 observable collection, 에 바인드됩니다. 여기에서 ListView를 업데이트 하시겠습니까?

내 모델입니다 모델에서

public class EquipmentMaintenanceModel : ChangeTracker, INotifyPropertyChanged 
    { 
     private string name; 
     private string address; 
     private string country; 

     public string Name 
     { 
      get { return this.name; } 
      set { this.name = value; } 
     } 

     public string Address 
     { 
      get { return this.address; } 
      set { this.address = value; } 
     } 
     public string Country 
     { 
      get { return this.country; } 
      set { this.country = value; } 
     } 
     private void OnPropertyChanged(string propertyName) 
     { 
      if (this.PropertyChanged != null) 
      { 
       this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
      } 
     } 
    } 

답변

0

, 당신은 당신이 속성 값을 설정하면하여 PropertyChanged를 해고해야합니다. 예 :

public string Name 
    { 
    get { return this.name; } 
    set 
    { 
     if(this.name != value) 
     { 
     this.name = value; 
     OnPropertyChanged(Name); 
     } 
    } 
    }