Label ContentStringFormat with new line

别等时光非礼了梦想. 提交于 2019-12-14 04:11:40

问题


I try to add new line inside Label ContentStringFormat:

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

Any suggestions ?


回答1:


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>
    


来源:https://stackoverflow.com/questions/32794574/label-contentstringformat-with-new-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!