2012-09-08 229 views
1

可能重複:
Why does the binding update without implementing INotifyPropertyChanged?Model屬性更改通知

我有WPF:

<TextBlock Grid.Row="0" Text="{Binding SomeProperty}" /> 
    <TextBox Grid.Row="1" Text="{Binding SomeProperty, UpdateSourceTrigger=PropertyChanged}" /> 

綁定到

 
class MyModel1 
{ 
    string _someProperty = string.Empty; 
    public string SomeProperty 
    { 
     get { return _someProperty; } 
     set { _someProperty = value; } 
    } 
} 

它allso作品有:

 
    class MyModel 
     { 
      public string SomeProperty { get; set; } 
     } 

,你看有沒有屬性更改通知,但同時我打字到文本框的TextBlock被更新。 我使用Visual C#express 2010,標準的WPF應用程序項目模板,標準控件,沒有片段,沒有額外的,與.NET 4客戶端配置文件。

  • 問題1:爲什麼它的工作原理?
  • 問題2:.NET 4的新功能?
  • 問題3:我如何能獲取有關屬性更改通知從 我的代碼無須在我的模型中的任何事件?

謝謝

+0

是的,這是dublicate ... :) – Dule

回答

0

1,如果這是工作,WPF的數據綁定引擎將數據綁定到PropertyDescriptor實例它包裝源屬性,如果源對象是一個普通的CLR對象和未實現INotifyPropertyChanged接口。

PropertyDescriptor.AddValueChanged()方法允許訂閱通知。

的變化如期望不同步,我們以定製該方面使用INotifyPropertyChanged

2你可以閱讀這篇文章,它是interessant

鏈接:http://msdn.microsoft.com/en-us/library/bb613588.aspx

+0

非常感謝你。隨着你提供的關鍵字,我發現這個東西是allready這裏討論[鏈接](http://stackoverflow.com/questions/7767218/why-does-the-binding-update-without-implementing-inotifypropertychanged) – Dule

+0

我'快樂幫助你Dule,如果你有另一個問題,我試圖幫助 –