locked
Using custom expressions to modify bound data? RRS feed

  • Question

  • I'm attempting to use custom expressions to mutate data I'm getting from an XML file but I can't seem to find any documentation on it.
    For example, my Xml-bound text block control has this as the Text property: 

    {Binding Mode=Default, Source={StaticResource rootDS}, XPath=/root/employee/@Rating}

    Which causes the textblock to look something like this:

    15

    What I want it to do is add the static text "rating +" before the value I get from the xml file such that it looks like this:

    rating +15.

    Is there any way to do this with custom expressions or will I need a value converter?


    Also, is there a way to aggregate several data-bound attributes together into a single textblock control? For example, if I wanted to bind firstName and lastName (two seperate attributes in the xml) into a single textblock is that possible?

    Thanks!
    • Edited by ErikSod Wednesday, June 11, 2008 7:52 PM Misspellings :)
    Wednesday, June 11, 2008 7:50 PM

Answers

  • Hi

    Unfortunately you cannot use custom expressions for this purpose. As you guessed you will have to write a Value Converter for such cases. Alternatively, if possible you could add another property to your data source which exposes the values in the format you desire. If you are using a web service of some sort then you can write your own wrapper around the service and expose the properties in the desired format.

    Thanks
    Jeetendra Kukreja [MSFT]
    Sunday, June 15, 2008 11:08 PM

All replies

  • Hi

    Unfortunately you cannot use custom expressions for this purpose. As you guessed you will have to write a Value Converter for such cases. Alternatively, if possible you could add another property to your data source which exposes the values in the format you desire. If you are using a web service of some sort then you can write your own wrapper around the service and expose the properties in the desired format.

    Thanks
    Jeetendra Kukreja [MSFT]
    Sunday, June 15, 2008 11:08 PM
  • Thanks for the response. I ended up using a CLR object with friendly-text properties that I then databound to the control. It was more work than I would have liked but it worked.
    Monday, June 23, 2008 11:08 PM