我有一个列表视图,其中还包含数据模板中的文本框,其中包含名称、地址、国家/地区等列。现在这个 listview 的 Itemsource 绑定到我的 viewmodel 类中模型的可观察集合。
我ObservableCollection<Model>
通过在 VM 中的某些条件下将名称和地址设为空来更新 ObjModel(类型),并且我可以在 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 绑定到 Model 对象 observable 集合,如何从这里更新 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));
}
}
}