我想更新绑定到列表视图项属性的文本块中的文本。这是我将文本块绑定到列表视图项的方式。
mWindow.xaml
<ListView Name="ListViewDetails"
ItemsSource="{Binding Persons}"
SelectedItem="{Binding CurrentPerson}">
...
</ListView>
<TextBlock>
<Run Text="{Binding ElementName=ListViewDetails, Path=SelectedItem.Office}"/>
...
</TextBlock>
如果列表视图中的项目属性发生更改,则文本不会更新。
mWindow.xaml.cs
public partial class mWindow: Window , INotifyPropertyChanged
{
private Person currentPerson;
public Person CurrentPerson
{
get
{
return currentPerson;
}
set
{
this.currentPerson = value;
this.NotifyPropertyChanged("CurrentPerson");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
var handler = this.PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
private void editLisView{
...
// refresh ListView
ICollectionView view =CollectionViewSource.GetDefaultView(ListViewInsuranceDetails.ItemsSource);
view.Refresh();
}
}