Changing the ContentStringFormat property of a Label in code behind

751 views Asked by At

Is it possible to change the ContentStringFormat property of a Label in code?

Take this XAML:

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

And this C#:

MyLabel.ContentFormatString = "Bye {0}";

When you debug this, you will see the property's value actually changes, but this is not visualized in the UI.

Is this possible?

1

There are 1 answers

0
Clemens On BEST ANSWER

Maybe not very elegant, but this works:

var content = MyLabel.Content;
MyLabel.Content = null;
MyLabel.ContentStringFormat = "Bye {0}";
MyLabel.Content = content;