2017-11-30 1 views
0

Ich habe eine Listenansicht, die Textbox in Datatemplate mit Spalten Name, Adresse, Land enthält. Nun ist die Itemsource dieser Listview verknüpft mit der beobachtbaren Sammlung eines Modells in meiner Viewmodel-Klasse.So aktualisieren Sie eine Listview von Viewmodel binded Modell beobachtbare Sammlung zu itemsource

Ich aktualisiere das ObjModel (vom Typ ObservableCollection<Model>), indem ich Name und Adresse leer, unter bestimmten Bedingungen in VM, und ich kann die Werte von Name, leer in meinem ObjModel-Objekt in Viewmodel-Klasse sehen. Aber diese Änderungen spiegeln sich nicht in der Benutzeroberfläche (ListView), fehlt mir etwas, wie Sie die Listview aktualisieren.

Meine Ansicht ist so etwas wie dieses:

<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> 

Ansicht Modell enthält:

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

Einige wo auf einigen Zustand kann ich

ObjModel[0].Name= string.Empty; 

Es in Listview nicht aktualisieren, weil Seine Itemsource ist an Object Observable Collection gebunden, how to Update ListView von hier?

Mein Modell ist:

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)); 
      } 
     } 
    } 

Antwort

0

In Ihrem Modell, müssen Sie Property feuern, wenn Sie den Wert einer Eigenschaft festgelegt. zB:

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