Yitschak Yitschak - 2 months ago 9
C# Question

Xaml- Escape '@' in binding path

My binding is like this:

<... SelectedItem={Binding ElementName=NAME, Path=MyProperty.@enum} />


The @enum is inner property and the @ is part of it's name.

The error I get is


Unexpected token


how can I escape the @?

Answer

The @ character is used to escape an identifier name that would otherwise be recognized as C# keyword. Since enum is a keyword in C#, you'll have to escape it, but that applies only to C#. The property name is still enum.

So the corrent property path is also MyProperty.enum:

SelectedItem="{Binding ElementName=NAME, Path=MyProperty.enum}"