Search code examples
wpflabelmultibinding

Label ContentStringFormat with new line


I try to add new line inside Label ContentStringFormat:

Content="{Binding Path=(my:MyData.Files)}"
ContentStringFormat="{}Number of files:\n {0:#,0}"

Any suggestions ?


Solution

  • You can't use C# escape characters in XAML code. For XAML there are other possibilities:

    • HEX represenation of CR/LF 
 (or just line feed 
):

      ContentStringFormat="{}Number of files: 
 {0:#,0}"

    • Bind to string that initially contains new line charachters where you need them

    • Use multibinding with Environment.NewLine

      <MultiBinding StringFormat="{}{0}{2}{1}" Mode="OneWay">
          <Binding Path="Property0" />
          <Binding Path="Property1" />
          <Binding Source="{x:Static System:Environment.NewLine}"/>
      </MultiBinding>