【问题标题】:Concatenate string via XAML通过 XAML 连接字符串
【发布时间】:2015-05-31 16:25:14
【问题描述】:

我在ProgressBar 中有这个标签,它的值来自Progressbar 值,我想在ProgressBar 值之后添加字符%

我尝试了两个不起作用的选项:

<Label Content="{Binding Progress}" ContentStringFormat="{}{0} %" />
<Label Content="{Binding Progress, StringFormat={}{0}%}" />

【问题讨论】:

标签: wpf xaml concatenation string.format


【解决方案1】:

例如ContentStringFormat:

<Label Content="{Binding Progress}" ContentStringFormat="{}{0} %" />

或者你使用Standard Numeric Format Specifier P

ContentStringFormat="{}{0:P}"

这一切都与String.Format非常相似。

【讨论】:

  • 就我而言,我需要将绑定变量与静态字符串连接起来。与此代码完美配合!
【解决方案2】:

请改用TextBlock

<ProgressBar Value="50" Name="prog" ... />

<TextBlock Text="{Binding Path=Value, ElementName=prog, StringFormat={}{0}%}"/>

【讨论】:

    猜你喜欢
    • 2011-01-01
    • 2017-06-24
    • 2016-09-12
    • 2016-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-14
    相关资源
    最近更新 更多