Charles Watson
Charles Watson

Reputation: 131

What is # in XAML StringFormat?

I am following the tutorial here. The example contains the line

<TextBlock Text="{Binding ElementName=wnd, Path=ActualWidth, StringFormat=Window width: {0:#,#.0}}" />

binding the window width to the textblock. If I remove "#,#", I notice I get the same result except there is no comma in the number if it's greater than 999. I see what it's doing. If I change it to

<TextBlock Text="{Binding ElementName=wnd, Path=ActualWidth, StringFormat=Window width: {0:##,#.0}}" />

I get the same thing. So my question is what does # mean exactly. Looked at MSDN and searched google but almost every example does not use any # signs.

Upvotes: 1

Views: 1128

Answers (1)

mm8
mm8

Reputation: 169330

# is a digit placeholder numeric format specifier in .NET that is replaced with the corresponding digit if one is present. Please refer to the docs for more information.

It has nothing to do with XAML really. You might as well use it programmatically when you for example call the ToString overload of a numeric type that accepts a format string.

Upvotes: 4

Related Questions