我可以将Label的内容设置为绑定表达式和静态值吗?

时间:2022-11-19 14:53:18

Is there a way to set a Label's Content property to both a Binding Expression AND a static string value? I want to be able to display something like this:

有没有办法将Label的Content属性设置为绑定表达式和静态字符串值?我希望能够显示如下内容:

"Current Value: [Value From Binding]"

I was thinking something like this would work, but apparently it doesn't:

我认为这样的东西会起作用,但显然它不会:

<Label Content="Current Value: {Binding ElementName=SomeTextBox, Path=Content}"/>

Thanks in advance!

提前致谢!

1 个解决方案

#1


If you are using .NET 3.5 SP1, you can use the ContentStringFormat:

如果您使用的是.NET 3.5 SP1,则可以使用ContentStringFormat:

<Label Content="{Binding ElementName=SomeTextBox, Path=Content}" ContentStringFormat="Current Value: {0}" />

#1


If you are using .NET 3.5 SP1, you can use the ContentStringFormat:

如果您使用的是.NET 3.5 SP1,则可以使用ContentStringFormat:

<Label Content="{Binding ElementName=SomeTextBox, Path=Content}" ContentStringFormat="Current Value: {0}" />