I am developing an Windows phone7 application, I have a .NET webservice that returns a List. This list should be bound to a ListBox.
Product is a class defined in the server and Visual Studio gets its definition from WSDL and creates a stub in my windows phone application.
What happens is that the list calls the “toString()” method in order to show the items in the GUI, so I have a strange string on my list. I would like to change to a user friendly string (Name – Quantity).
To do that, I want to override the toString() method, but changing it in the server definition doesn’t help because methods are not exposed in the WSDL.
Changing the stub myself would cause me to lose the data when I refresh or change the reference.
I think it is a very often case, so there should be a solution, which I am missing. So please, how can I define the method ToString() in the windows phone7 to this object so I can bind it to the list?
Thank you,
Oscar
The correct approach is to take the raw data coming in from the WS and translate it to a representative model, in adherence to the MVVM guidelines and seperating yourself from concerns on the server side. Creating a proxy essentially between you and the WS.
Furthermore, once you have done this you could simply create a property on that model which you can then bind to and could return the data as you need, making use of the
DisplayMemberPathproperty.Your model could then be something like…