wcfWebサービスを使用するwpfアプリがあります。それは私のWebサービスとアプリなので、どちらの側にも変更を加えることができます。Visual Studioによって自動的に生成される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をリッスンし、プログラムで値を変更すると、イベントが2回発生します。1回は変更したため、もう1回はwpfがバインディングを介して変更したためです。
ありがとう、