Search code examples
c#wpfxamlgroupbox

HeaderStringFormat issue when using Curly Brace next to the beginning quote


I have the following XAML. The idea is to append the text " For Report" after a string that is coming from a bound XML file.

<GroupBox Header="{Binding XMLData.Element[HeadingText].Value}" 
          HeaderStringFormat="For Report">

When I add {0} to the beginning of the HeadingStringFormat String like so, the application ignores the HeaderStringFormat and simply puts up the databound value.

<GroupBox Header="{Binding XMLData.Element[HeadingText].Value}" 
          HeaderStringFormat="{0} For Report">

However, when I add a single space (or any other character for that matter) after the quote, but prior to the left {, the application works fine.

<GroupBox Header="{Binding XMLData.Element[HeadingText].Value}" 
          HeaderStringFormat=" {0} For Report" >

In the first example, the editor seems to think that the string (between the quotes) isn't a string anymore, but if I put in that space, it's happy.


Solution

  • Try prefixing your format string with {}. This should work:

    <GroupBox Header="{Binding XMLData.Element[HeadingText].Value}" 
              HeaderStringFormat="{}{0} For Report">
    

    For further information, see MSDN: {} Escape Sequence / Markup Extension