Search code examples
c#wpfwindowsxamlwindows-phone

XAML bind to a property with @


i Have a class which has a @base property. The @ is required because "base" is a reserved word of the C# language.

How do i bind from XAML to this property?


Solution

  • base is a keyword in C# but not in XAML, therefore you can simply write...

    <TextBlock Text="{Binding base}" />
    

    if you have something like this in the current DataContext:

    public string @base { get { return "Hello, World!"; } }
    

    Keep in mind that @ is not part of the property name in C#, it just means the following token is an identifier. The real property name is base even though you have to refer to it as @base in C#.