I've bound the XamMaskedEditor to a TimeSpan property in my class and as long as I use a mask of "hh:mm:ss" it works fine. I'd like to use a mask of "hh:mm tt" instead so that I get a display formatted like this "10:59 PM" but I can't seem to get it working. Could someone take a look at the attached project and give some advice?
Thanks!
Hello,
I have modified the sample, so now it shows AM/PM, but I can say that it is not recommended to use TimeSpan to show DateTime and this is why when you use Mask for a DateTime it doesn’t work correctly. I have created a workaround, but if it doesn’t satisfies all your needs I can suggest you use DateTime value instead of TimeSpan.
Hello Stefan,
I appreciate your work on this. I think however that maybe I wasn't clear enough in my original post. I want the display formatted like this "10:59 PM". Maybe to put it more clearly, I want the editing and display modes to be in an AM/PM format. I know that a TimeSpan really isn't about AM/PM but rather an amount of time. The application on which I'm working uses a TimeSpan as the amount of time after midnight at which to begin a job. The date is irrelevant because we don't care about the date, only the time. That is why we're using a TimeSpan instead of a DateTime which would cause a lot of extra baggage having to always extract the time or strip the date when saving to the database etc.
The converter you suggested doesn't seem to handle this at all as it seems to know nothing about AM/PM. I made a few modification to it and spent some time trying to make it work but was unable to get it working. Would you mind looking at the modified version I have attached?
I had also hoped to have a combo box prefilled with times to pick from, but figured that would be phase two since the spin buttons are more important to me right now. Maybe you have a better suggestion than the path I'm going?
Thanks for your help!
Thank you for your post. I have been looking into it and the sample you sent and modified it, so now it works as you want. Basically I set the XamMaskedEditor’s ValueToTextConverter to a Converter where I implemented the ConvertBack method, because the Editor cannot convert the value displayed in it into TimeSpan by itself. Please let me know if this helps you r you need further assistance on this matter.
Looking forward for your reply.