C# 更新/刷新绑定到wpf/xaml中另一个元素属性的TextBlock
我想更新绑定到listview项属性的textblock中的文本。这是我将textblock绑定到listview项的方式 mWindow.xamlC# 更新/刷新绑定到wpf/xaml中另一个元素属性的TextBlock,c#,wpf,xaml,listview,textblock,C#,Wpf,Xaml,Listview,Textblock,我想更新绑定到listview项属性的textblock中的文本。这是我将textblock绑定到listview项的方式 mWindow.xaml <ListView Name="ListViewDetails" ItemsSource="{Binding Persons}" SelectedItem="{Binding CurrentPerson}"> ... </ListView> <Te
<ListView Name="ListViewDetails"
ItemsSource="{Binding Persons}"
SelectedItem="{Binding CurrentPerson}">
...
</ListView>
<TextBlock>
<Run Text="{Binding ElementName=ListViewDetails, Path=SelectedItem.Office}"/>
...
</TextBlock>
我认为我必须为CurrentPerson属性实现INotifyPropertyChanged。当我为person类实现INotifyPropertyChanged时,它起作用。绑定的项是否实现INotifyPropertyChanged?如果绑定未中断,请检查输出窗口@查理:是的,我知道,但我不知道我的解决方案是否正确。
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();
}
}