WPF Xaml Stringformat

Asked

Viewed 335 times

3

Good afternoon guys, I’m having a problem kind of ridiculous, but I can’t find the solution.

I’m trying some stringFormat as StringFormat={}{0:#,#.00}} and StringFormat=N2}, besides StringFormat='c', but apart from the first that does not compile (I do not know why) the others insert 2 decimal places (value + 00), however I would like him to consider the last two value houses as being the cents.

<DataGridTextColumn Header="Valor Fator" Binding="{Binding 
PendenciaValorFator, Mode=TwoWay, StringFormat=N2, 
UpdateSourceTrigger=PropertyChanged}" IsReadOnly="False">

I am sending a decimal with this format: 728001 and it is showing 728.001,00, however I would like it to show 7.280,01.

Adding, I need to be sent a numerical value to the grid otherwise when doing the "order" it will do by string thus, putting first the value 1.111,11 instead of 999,99.

  • To show how you want the string has to be "7280.01"

  • I put in the database 7280,01 and 7280,01, the result was 728,001,00

  • What is the type of PendenciaValorFator?

  • I’m doing the test as decimal, because when I was using as a string it was ordering as a string, putting 1.111.11 in front of 999.99.

  • 1

    I did not explain myself well in my first commit. What I meant is that for the value to be formatted like this:"7280.01", the value of PendenciaValorFator(decimal type) must have decimal places: PendenciaValorFator = 7280.01;

  • If you play 728001 the WPF will understand that is seven hundred and twenty eight thousand and one, and will format to 728001,00 or 728,001.00 according to the culture. You need to create a Converter to customize this;

  • @ramaral if you want to put as answer, I will accept!

Show 2 more comments

1 answer

1


In order for the string resulting from the formatting to have the decimals as you want it is necessary that the source value, in this case PendenciaValorFator, represents that value to those decimal places.

That is, for the result to be "7280.01" it is necessary that PendenciaValorFator be equal to 7280.01 and not 728001.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.