2016-01-17 38 views
0

我有一個Windows 10通用應用程序,帶有XAML中的ListView和ObservableCollection<Contact>,它通過ItemsSource="{x:Bind Messenger.Contacts}"綁定到ListView。現在我想讓ListView更新一個listview元素的特定邊界(也是通過x:Bind)屬性的文本,如果屬性發生改變的話。我的ContactClass實現INotifyPropertyChanged,是公開的,並且在每個屬性設置器中,我使用正確的屬性名稱觸發NotifyPropertyChanged。Windows 10通用應用程序:PropertyChanged事件始終爲空ListView

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

但我的ListView從不更新和PropertyChanged事件始終爲空。在我讀過的其他問題中,ListView將自動訂閱。但是,爲什麼我的事件總是空?我如何強制更新特定的ListView項目?

回答

2

最有可能與您的TextBlock的x:Bind to Text屬性相關的問題。 x:Bind的默認綁定模式是OneTime。您需要將其更改爲OneWay以獲得您想要的行爲。您可以在我的博客中閱讀有關此更改的更多信息:http://iwindroid.me/binding-and-performance/

+0

不錯!謝謝,這工作。 – user2429841

相關問題