How can I escape the slash character in the WPF binding path or how to work?

I am just learning WPF and I outlined a table from a data source in a window that generated XAML for each column.

Some of these columns had names that caused the following:

<DataGridTextColumn x:Name="_Rev_UnitColumn" Binding="{Binding Path=Rev/Unit}" Header="Rev/Unit" Width="SizeToHeader" /> 

This causes the column to become empty (e.g. me).

+6
source share
2 answers

There is an article in MSDN on property paths that has a section on escape characters:

Inside the indexers ([]), the carriage character (^) escapes the next character.

You should avoid (using XML objects) certain characters that are special for defining an XML language. Use and to escape the "&" character. Use> to avoid the end of the ">" tag.

You should avoid (using the backslash \) characters that are special for the WPF XAML parser to handle markup extensions.

  • The backslash (\) is the escape character itself.
  • An equal sign (=) separates the property name from the property value.
  • Comma (,) shares properties.
  • The curly brace (}) is the end of the markup extension.

A slash is not listed here, so I don't know if a backslash escape will work, but you can try it.

(How do you have that property name? It seems like illegality in both XML and C #)

+4
source

I (random case):

 <DataGridTextColumn x:Name="_Rev_UnitColumn" Binding="{Binding Path=[Rev/Unit]}" Header="Rev/Unit" Width="SizeToHeader" /> 

And as a result, everything worked as I expected. Looking at it again, I think HB Quote MSDN tells me that. When I read this (initially on MSDN, before I even posted this question, and then here again), I just didn’t understand what the “Internal indexes -comma" are - the caret character (^) escapes the next character. "

+3
source

Source: https://habr.com/ru/post/892913/


All Articles