将referenceequals更改为reference.cs中的equals
我有一个使用 wcf web 服务的 wpf 应用程序。它是我的网络服务和应用程序,因此我可以对任一侧进行更改。在由 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 并以编程方式更改值,然后事件发生两次,一次是因为我更改了它,一次是因为 wpf 通过绑定更改了它。
谢谢,
I have a wpf app that uses a wcf webservice. Its my webservice and app, so I can make changes to either side. In the Reference.cs file that gets automatically genereated by visual studio it uses this code for the property changed event:
[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");
}
}
}
For strings though what I would really like is this:
[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");
}
}
}
}
That way the property changed event would not go off if the value is the same. Why this is an issue is because I listen to the OnPreviewTextInput of a textbox and change the value programmatically, then the event goes off twice, once because I changed it and once because wpf changed it via binding.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您同时控制服务器和客户端,则可以在单独的程序集中定义类型,然后从两个项目中引用该类型。
在 WCF 引用添加对话框高级设置中,您可以告诉它重用类型,然后它将使用客户端上的通用程序集中存在的数据对象的任何实现。
If you control both the server and the client, you can define your type in a seperate assembly, which you then reference from both projects.
In the WCF reference add dialog advanced settings you can tell it to re-use types, then it will use whatever implementation of your data object exists in the common assembly on the client.