Share via


Escaping XPath syntax in WPF Databinding

Another thing that recently came up which isn't documented that I thought I'd pass on: if you have characters such as = or " or ' in your XPath when doing databinding, the parser will be unhappy, unless you escape those characters with \.  So, you might end up with something like this:

<TextBlock Text="{Binding Source={StaticResource xdp}, XPath=Element[@ID\=100]}"/>

Using the backslash as an escape for XPath isn't documented yet in the SDK or, at least, I couldn't find it...

Comments

  • Anonymous
    May 30, 2006
    The character is also useful for escaping { and } if you want to use them literally (rather than indicating a markup extension)
  • Anonymous
    May 30, 2006
    It seems to me that the blogpost doesn't render as you intended.

    "So, you might end up with something like this:" - what?
  • Anonymous
    May 31, 2006
    The comment has been removed