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?

3
  • 1
    formatting of Label content requires another approach: stackoverflow.com/questions/4206612/… Commented Oct 21, 2016 at 6:39
  • It seems StringFormat works only if the TargetType is of type string, here Content property is of type object I guess. Commented Oct 21, 2016 at 6:44
  • You need to escape string so: StringFormat={}{0:N}. Commented Oct 21, 2016 at 7:14

2 Answers 2

2

you have to use ContentStringformat when using a Label

<Label x:Name="labelCounterCamera" Margin="5,2" 
   Content="{Binding CounterCamera}"
   ContentStringFormat="{}{0:N}" />
Sign up to request clarification or add additional context in comments.

Comments

0

Try moving the format string inside the placeholder token.

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

{0:N} instead of N{0}

4 Comments

No, it doesn't compile.
You need to escape using StringFormat={}{0:N}
@apc Now, it compiles but I get no format.
Check the immediate window output for errors, this should would with a TextBlock however I'm not sure about Labels so see blindmeis answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.