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 (3)
  1. JosephCooney says:

    The character is also useful for escaping { and } if you want to use them literally (rather than indicating a markup extension)

  2. Klaus says:

    It seems to me that the blogpost doesn’t render as you intended.

    "So, you might end up with something like this:" – what?

  3. karstenj says:

    Whoops forgot the little code snippet: thanks for the head’s up.

Comments are closed.

Skip to main content