0

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?

VansFannel
  • 43,504
  • 101
  • 342
  • 588
  • 1
    formatting of Label content requires another approach: http://stackoverflow.com/questions/4206612/wpf-stringformat-on-label-content – ASh Oct 21 '16 at 06:39
  • It seems `StringFormat` works only if the `TargetType` is of type `string`, here `Content` property is of type `object` I guess. – Mat J Oct 21 '16 at 06:44
  • You need to escape string so: `StringFormat={}{0:N}`. – XAMlMAX Oct 21 '16 at 07:14

2 Answers2

1

you have to use ContentStringformat when using a Label

<Label x:Name="labelCounterCamera" Margin="5,2" 
   Content="{Binding CounterCamera}"
   ContentStringFormat="{}{0:N}" />
blindmeis
  • 21,626
  • 7
  • 52
  • 71
0

Try moving the format string inside the placeholder token.

Content="{Binding CounterCamera, StringFormat={0:N}}"

{0:N} instead of N{0}

Gusdor
  • 13,624
  • 2
  • 51
  • 62