VansFannel VansFannel - 1 month ago 6
C# Question

WPF Binding StringFormat doesn't change the output

I'm developing a WPF with C# and .NET Framework 4.6.1.

I have this number 1010 and I want to show it like this 1.010 (I'm Spanish).

To do it, I have modified XAML:

<Label x:Name="labelCounterCamera" Margin="5,2"
Content="{Binding CounterCamera, StringFormat=N{0}}" />


But it shows the number without format: 1010.

CounterCamera
is:

public uint CounterCamera
{
get { return counterCamera; }

set
{
if (!value.Equals(counterCamera))
{
counterCamera = value;
RaisePropertyChangedEvent("CounterCamera");
}
}
}


Why that StringFormat doesn't work? What am I doing wrong?

Answer

you have to use ContentStringformat when using a Label

<Label x:Name="labelCounterCamera" Margin="5,2" 
   Content="{Binding CounterCamera}"
   ContentStringFormat="{}{0:N}" />
Comments