wpf 通过 XAML 连接字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30559718/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:10:16  来源:igfitidea点击:

Concatenate string via XAML

wpfxamlconcatenationstring.format

提问by Verint Verint

I have this label inside ProgressBarthat take it's value form the Progressbarvalue and i want to add the char %after the ProgressBarvalue.

我在里面有这个标签ProgressBar,它从值中获取它的Progressbar值,我想%ProgressBar值后添加字符。

I have tried two options that not working:

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

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

回答by LPL

e.g. with ContentStringFormat:

例如使用ContentStringFormat

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

or you use Standard Numeric Format Specifier P

或者您使用标准数字格式说明符 P

ContentStringFormat="{}{0:P}"

This all is very similar to String.Format.

这一切都非常相似String.Format

回答by Mike Eason

Use a TextBlockinstead.

使用 aTextBlock代替。

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

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