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
  • 45,055
  • 107
  • 359
  • 626
  • 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
  • 22,175
  • 7
  • 55
  • 74
0

Try moving the format string inside the placeholder token.

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

{0:N} instead of N{0}

Gusdor
  • 14,001
  • 2
  • 52
  • 64
Steffen Maucy
  • 132
  • 1
  • 7