用新行标记ContentStringFormat [英] Label ContentStringFormat with new line

查看:348
本文介绍了用新行标记ContentStringFormat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在Label ContentStringFormat内添加新行:

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

有什么建议吗?

推荐答案

您不能在XAML代码中使用C#转义字符.对于XAML,还有其他可能性:

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

  • CR/LF 
的十六进制表示形式(或仅换行
):

  • 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

Environment.NewLine

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

这篇关于用新行标记ContentStringFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆