2
我有一個使用wcf webservice的wpf應用程序。它是我的web服務和應用程序,所以我可以對任何一方進行更改。在這就會自動由Visual Studio genereated的Reference.cs文件,它使用的屬性更改事件驗證碼:將referenceequals更改爲reference.cs中的等於
[System.Runtime.Serialization.DataMemberAttribute()]
public string Value {
get {
return this.ValueField;
}
set {
if ((object.ReferenceEquals(this.ValueField, value) != true)) {
this.ValueField = value;
this.RaisePropertyChanged("Value");
}
}
}
對於字符串,雖然我真的想是這樣的:
[System.Runtime.Serialization.DataMemberAttribute()]
public string Value {
get {
return this.ValueField;
}
set {
if ((object.ReferenceEquals(this.ValueField, value) != true)) {
if (this.ValueField != value)
{
this.ValueField = value;
this.RaisePropertyChanged("Value");
}
}
}
}
這樣如果值相同,屬性更改事件不會關閉。爲什麼這是一個問題,因爲我聽文本框的OnPreviewTextInput並以編程方式更改值,然後事件關閉兩次,一次是因爲我更改了它,一次是因爲wpf通過綁定更改了它。
感謝,
根據我的解決方案是如何拆分出來的,這是行不通的,有沒有辦法在自動生成的reference.cs文件中覆蓋該方法? – odyth 2010-12-22 00:11:53
@odyth - 如果沒有其他選項出現,我有時會編輯reference.cs文件。在這些情況下,問題是您必須記住您編輯了文件,並在更改時再次進行相同的更改。 – Joon 2011-08-21 10:06:55