3

I have imported a wsdl and i have all my client classes now. I want to add an additional (computed) property to a class for wpf binding purposes. I want a computed property to display along side (and based on) properties returned from the server (in a grid)

to me the logical thing was to create a partial class, same namespace and same class name as the wcf generated class, and add the new computed property to this partial class

    namespace TestClient.WSCompanySearch  //same namespace as the generated class from wsdl
    {
        public partial class Company  //same class returned by wsdl
        {
            public bool IsValid
            {
                get {

                    if ((this.CloseDate < DateTime.Now) || (this.Rooms == 0))
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
            }                       
        }
    }

This extra property is definitely there, and i can see it if i code to it, but when i bind, it's as if the custom property is ignored. The breakpoint in the getter is not called, thus indicating that it's not getting called.

Seymour
  • 7,043
  • 12
  • 44
  • 51
Crudler
  • 2,194
  • 3
  • 30
  • 57

3 Answers3

0

You might be able to get the same result by using a Converter for the columns where you want that computed property.

dutzu
  • 3,883
  • 13
  • 19
  • This is how you cand send the object that the row is binding to, to a converter http://stackoverflow.com/questions/4335068/wpf-pass-parent-binding-object-to-the-converter and inside the Convert method of the converter you can insert the code that you would have in the Getter – dutzu Dec 14 '12 at 09:18
  • i'm assuming you don't have the grid set to AutoGenerateColumns, so then you just have to add a new column in which you specify the converter in your binding – dutzu Dec 14 '12 at 09:21
  • thanks. i managed to get my method to work in the end. thanks for the help – Crudler Dec 14 '12 at 11:25
0

My method was correct in the end. just a combination of

  1. my logic was incorrect inside the new property
  2. i needed to turn off "Just My Code" debugging for the breakpoint in the new class to work. I guess VS thinks that it was part of th generated code and wanted to not debug it
Crudler
  • 2,194
  • 3
  • 30
  • 57
0

had the same problem, I have to add a private set method in order to be able to deserialize the object

Rob Sedgwick
  • 4,342
  • 6
  • 50
  • 87
  • you can add `[XmlIgnore]` attribute to the custom property to Deserializer ignore it – Ivan Ferrer Villa May 17 '17 at 16:03
  • It's the opposite situation that this problem relates to, where you have a read-only property that you want to deserialize – Rob Sedgwick May 17 '17 at 17:06
  • it works for me as I say. If I remove those `[XmlIgnore]` attributes from my custom public properties created in a partial class, it gives me an error when trying to deserialize. If I add them back, all goes ok. I think it is reasonable, because Xml Deserializer knows nothing about those 'new' properties, then `[XmlIgnore]` does what it says. (please excuse my english) – Ivan Ferrer Villa May 18 '17 at 22:08