Yitschak Yitschak - 1 year ago 162
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 Source

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}"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download