1

I will start by saying that I am completely new to WPF. I am trying to learn and diagnose an existing application and I had a question I was hoping someone could answer.

I noticed when a user enters a percentage, it requires the user to enter a decimal value (which makes sense), but then it displays it as a percentage like if the user enters .50 it is displayed in the cell as "50%" (after leaving the cell of course). The reason it behaves this way is obvious to me, because the format is set to "{0:P}".

I wanted to allow the users to enter "50 %" so I created a converter (that for instance converts "50 %" to .5 and it works great).

What puzzles me is why isn't a converter needed for the currency fields (Format = "{0:C}")? I am surprised that the DataGrid allows the user to enter dollar signs, commas, etc and then coverts them to a decimal (money type in SQL).

Is there some automagic stuff going on with the Currency Format (or some other property that I just haven't found in the code yet) or is there a Converter somewhere that I haven't discovered?

How is this working and if it is some automagic stuff, why isn't percentages handled automagically in a similar manner?

Shayne
  • 1,083
  • 3
  • 18
  • 30

1 Answers1

0

I just ran across this issue. Since no one has provided an answer in 9 months, I'm going to give my best guess. There appears to be a built in currency converter (see this answer) and I suspect somehow the FormatString for currency uses this built-in converter behind the scenes. The built in ZoomPercentageConverter doesn't appear to do what's needed so I'm guessing the P StringFormat is just dumber, too bad.

Community
  • 1
  • 1
Tod
  • 8,192
  • 5
  • 52
  • 93
  • That is pretty much what I found too. Since then, I have moved on to a 3rd party Data Grid that provides much better scrolling performance and handles this "percentage" issue much better anyway.... – Shayne Dec 22 '11 at 16:25
  • Glad you found a good solution. I asked a similar question to yours and decided to go with the approach of using a style/trigger so that it looks like 10% but when you click to edit it goes to .10. If you have any interest (the general style/trigger/databinding is pretty useful) I [wrote up a blog entry](http://syncor.blogspot.com/2011/12/editing-percentages-in-xaml-part-ii.html) so I would remember how to do it. – Tod Dec 22 '11 at 19:19