user2740190
user2740190

Reputation:

Writing a mask for formatting the time

Currently if something like "1230AM" comes in, it will get formatted correctly and will show as

"12:30 AM"

But if something like " 830AM" comes in, it will get formatted and shown as " 8:30 AM" BUT I need it to show as "08:30 AM" How can I do this? Notice those blank spaces before the number 8

The in-house built! masked text box is currently using a style defined like this which I think needs to be changed:

<Style x:Key="MyTimeMaskStyle" TargetType="controls:MyMaskedTextBox" BasedOn="{StaticResource MyMaskedTextBoxStyle}">
    <Setter Property="MaskType" Value="Standard" />
    <Setter Property="Mask" Value="##:## ll"></Setter>
    <Setter Property="Placeholder" Value=" " />
</Style>

Upvotes: 0

Views: 87

Answers (1)

BobakDotA
BobakDotA

Reputation: 323

You can't o that on the string format and mask level. Don't spend more time of that rabbit hole.

Couple of options I would suggest:

  1. Find out where data is getting loaded and massage it before it gets to the binding.
  2. Write a converter and do the same, massage it and make sure it has a leading zero if the th fitst character of data coming in is a space.

Upvotes: 1

Related Questions