简体   繁体   中英

Windows 10 Universal App:PropertyChanged Event is always null ListView

I have a Windows 10 Universal App with a ListView in XAML and a ObservableCollection<Contact> which is bound to the ListView via ItemsSource="{x:Bind Messenger.Contacts}" . Now I want the ListView to update text the of the specific bound (also via x:Bind) property of a listview element if the property is changed. My ContactClass implements INotifyPropertyChanged, is public and in every property setter I fire NotifyPropertyChanged with the correct property name.

 public class Contact : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected string name;

        public string Name
        { 
            get
            {
                return this.name;
            }
            set
            {
                this.name= value;
                NotifyPropertyChanged("Name");
            }
        }
protected virtual void NotifyPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = this.PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
 }

But my ListView is never updated and the PropertyChanged Event is always null. In other Questions I have read, that the ListView will automatically subscribe. But why is my Event always null? How I can force an update of the specific ListView Item?

The problem most likely related to the x:Bind to Text property of your TextBlock. The default binding mode of x:Bind is OneTime. You need to change it to OneWay to get your desired behavior. You can read more about this change in my blog: http://iwindroid.me/binding-and-performance/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM