2017-11-30 27 views
0

私はリストビューを持っています。このビューには、名前、住所、国の列を持つデータ型のテキストボックスがあります。 このリストビューのItemsourceは、私のviewmodelクラスのモデルの観測可能なコレクションにバインドされています。viewmodelからリストビューを更新してitemsourceにバインドしたモデルobservableコレクションを更新する方法

私はObjModel(タイプObservableCollection<Model>)を名前とアドレスを空にすることでVMのいくつかの状態で更新しています。viewmodelクラスのObjModelオブジェクトのnameという名前が空であることがわかります。 しかし、これらの変更は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はModelオブジェクトobservableコレクションにバインドされ、ここからリストビューを更新しますか?

私のモデルである:あなたのモデルで

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); 
     } 
    } 
    } 
関連する問題