在后面的代码中更改Label的ContentStringFormat属性

时间:2015-06-24 09:44:23

标签: c# wpf label code-behind

是否可以在代码中更改Label的ContentStringFormat属性?

拿这个XAML:

<Label ContentFormatString="Hello {0}" Content="John" x:Name="MyLabel" />

这个C#:

MyLabel.ContentFormatString = "Bye {0}";

调试时,您会看到属性的值实际发生了变化,但在UI中无法显示。

这可能吗?

1 个答案:

答案 0 :(得分:1)

也许不是很优雅,但这很有效:

var content = MyLabel.Content;
MyLabel.Content = null;
MyLabel.ContentStringFormat = "Bye {0}";
MyLabel.Content = content;
相关问题