Peter
Peter

Reputation: 14108

Changing the ContentStringFormat property of a Label in code behind

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?

Upvotes: 1

Views: 761

Answers (1)

Clemens
Clemens

Reputation: 128070

Maybe not very elegant, but this works:

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

Upvotes: 1

Related Questions