Ingó Vals
Ingó Vals

Reputation: 4898

How to convert multiple textboxes to one value

In my WPF application the user is inputting a GPS coordinates in the format of Degrees : Minutes : Seconds as decimal fraction of minutes.

So 60° 30' 45" would be entered as 60° 30.750' .

I then store it as a pure decimal number so the above example would be stored as 60.5125.

The idea was that so the users wouldn't mess up the input it would be set in 3 different textboxes. One for Degrees, other for Minutes and one for the fractionalSeconds. It's somewhat bad that one of the numbers is seperated into two textboxes but if they have to type the whole number in the are afraid of all the point or comma confusion and that they could mess up.

So one thing I thought might work was a IMultiValueConverter but it seems to only work with MultiBindings which is something I'm not doing here.

Currently my solution is to bind to different properties and do all the calculations in code behind but I'm not really happy about the fractional bit. I assume 3 fractional letters but if they enter only 7 and assume 0.700 but get 0.007 so I thought I would have to do a string format bit.

Is there a better solution out there. Can I use MultiValueConverter for something like this?

Upvotes: 0

Views: 325

Answers (2)

LPL
LPL

Reputation: 17083

You could use a Masked TextBox. This implementation uses MaskedTextProvider which is a .net class.

Upvotes: 1

Phil
Phil

Reputation: 43011

You could try using a MaskedTextBox, such as the one from the Extended WPF Toolkit.

Upvotes: 2

Related Questions