Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
245
XamCurrencyInput and string based mask
posted

Hi,

I am using the XamCurrencyInput to bind to a decimal? value on my ViewModel. I am using the ValueToTextConverter and ValueToDisplayText converters to convert the decimal to string and vice-versa. I need to do this as I have the situation where certain numbers need to be displayed in the following format:

  • 104-02
  • 103-07+
  • 99-29:7
  • 99-28

So the rules I use to create the mask are:

  1. Positions 1 to 3: Optional numerical characters
  2. Position 4: A - (minus) symbol. This does not mean 'minus' - it is equivalent to a decimal place. In my mask, I have it working by 'escaping' it.
  3. Positions 5 to 6: Optional numerical characters
  4. Position 7: Either a + or a : symbol can be placed here.
  5. Position 8: Optional numerical character.

Therefore, I need to have a mask like the following:

nnn\-nn{char:1:+:}n

But this doesn't work. The 'nnn\-nn' part works ok, but no further than that. 

I'm not sure whether the mask is not correct, or is incompatible with the Mask property on the control. Please note that I have some success if I insert a [SPACE] character before the {char:1:+:}, but this then leaves the display value with a SPACE in it which I do not want.

Below is my XAML usage. Please note that I have NOT set the DataMode or the DisplayMode to 'Raw'.

<ig:XamCurrencyInput x:Name="PriceBox" 
                FontSize="16"
                Grid.Row="1"
                Margin="1,1,-1,2"
                Mask="{Binding Mask}"
                PromptChar=""
                SpinButtonDisplayMode="Always"
                SpinIncrement="{Binding SpinIncrement}"
                TrimFractionalZeros="False"                             
                Value="{Binding Value}"                              
                ValueToDisplayTextConverter="{StaticResource MyConverter}"
                ValueToTextConverter="{StaticResource MyConverter}" />

Can anyone please advise how I can get this mask to work or confirm that it is not possible? For now, I will have to use a RegEdit on the ValueConstraint but I'd prefer to get the Mask working.

Regards,

Slugman