{} Escape Sequence / Markup Extension

Provides the XAML escape sequence for attribute values, allowing the subsequent values in the attribute to be interpreted as a literal.

XAML Attribute Usage

<object property="{}literalValue" .../>

XAML Property Element Usage

<object>
  <object.property>
    {}literalValue
  </object.property>
</object>

XAML Values

literalValue

The literal string being escaped.

Remarks

The {} escape sequence is used to escape the { and } as used for markup extensions in attribute syntax. The escape sequence itself is not strictly speaking a markup extension and is not backed by a class. All other markup extensions in XAML use the { and } characters as recognized by XAML processor implementations for escaping the handling of attribute values to be other than literals or handler references. Only the special case of the two curly braces adjacent will be treated as the escape sequence. For more information, see Markup Extensions and XAML.

This escape sequence is useful when you want to set the literal character { as the first character of a value.

Note that a quotation mark character (") cannot be escaped in this way. If you need to set a quotation mark character as a property value for a noncontent property, use property element syntax and place the quotation mark as a string inside the property element, or use an XML character entity. For a content property, the quotation mark can be the entire content.

The {} escape sequence is frequently required when specifying an XML type that must include a namespace qualifier in a location where XAML markup extension might appear. This includes the beginning of an XAML attribute value, and within a markup extension, immediately after an equal-sign. The following example shows escapes for an XML namespace that appears at the beginning of a XAML attribute value.

<StackPanel Name="stacky">
  <StackPanel.Resources>
    <DataTemplate DataType="{}{http://planetsNS}Planet" >
      <StackPanel Orientation="Horizontal">
        <TextBlock Width="100" Text="{Binding Path=Element[{http://planetsNS}DiameterKM].Value}" />
        <TextBlock Width="100" Text="{Binding Path=Attribute[Name].Value}" />
        <TextBlock Text="{Binding Path=Element[{http://planetsNS}Details].Value}" /> 
      </StackPanel>
    </DataTemplate>
  </StackPanel.Resources>

See Also

Concepts

XAML Overview

Markup Extensions and XAML

Reference

XML Character Entities and XAML