0

我想更新绑定到列表视图项属性的文本块中的文本。这是我将文本块绑定到列表视图项的方式。

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

}
4

1 回答 1

0

我以为我必须为 CurrentPerson 属性实现 INotifyPropertyChanged。当我为人员类实现 INotifyPropertyChanged 时,它可以工作。

于 2012-12-27T09:25:07.343 回答