2

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,

odyth
  • 4,324
  • 3
  • 37
  • 45

1 Answers1

0

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.

Joon
  • 2,127
  • 1
  • 22
  • 40
  • Based on how my solution is split out that will not work, is there a way to override the method in the automatically generated reference.cs file? – odyth Dec 22 '10 at 00:11
  • @odyth - I sometimes edit reference.cs files when no other option presents itself. The issue in those cases is that you have to remember that you edited the file, and make those same changes again whenever it is changed. – Joon Aug 21 '11 at 10:06