Welcome to the Xceed Community | Help
Community Search  
More Search Options

ValueToMaskedTextConverter

Sort Posts: Previous Next
  •  07-27-2010, 9:49 PM Post no. 27759

    ValueToMaskedTextConverter

    I can't seem to get this converter to work 100%. It doesn't appear to support all of the mask options and the documentation simply points to the MaskedTextProvider Class.

    For example if I set the mask (ConverterParameter) to "999,990.00" and the value is "10.99" what's displayed is "000,010.99". If the value is null I get "   ,   ." What I want is "10.99". I've tried "0.00" but if the value exceeds 9.99 the value is treated like a null.  Here are the relvent code snippets:

    xmlns:DataGrid="clr-namespace:Xceed.Wpf.DataGrid;assembly=Xceed.Wpf.DataGrid"

    xmlns:DataGrid2="http://schemas.xceed.com/wpf/xaml/datagrid"

     

     

    <DataGrid2:ValueToMaskedTextConverter x:Key="maskedTextConverter" />

    <DataTemplate x:Key="numericUnitsCellTemplate">

    <TextBlock>

    <TextBlock.Text>

    <Binding Converter="{StaticResource maskedTextConverter}"

    ConverterParameter="999,990.00" />

    </TextBlock.Text>

    </TextBlock>

    </DataTemplate>

     

    <DataGrid2:Column MinWidth="60"

    Width="10*"

    FieldName="QuantityOrdered"

    Title="Ordered Quantity"

    DataGrid:DataGridColumnAlignment.ColumnAlignment="Right"

    TitleTemplate="{StaticResource titleTemplate}"

    CellContentTemplate="{StaticResource numericUnitsCellTemplate}" />

  •  07-28-2010, 9:02 AM Post no. 27765 in reply to 27759

    Re: ValueToMaskedTextConverter

    I think maybe what you're looking for is

    ###,##0.00

    As per http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.mask%28v=VS.80%29.aspx:

    Masking element "#" -  Digit or space, optional. If this position is blank in the mask, it will be rendered as a space in the Text property. Plus (+) and minus (-) signs are allowed.

    While "9" is also a "Digit or space, optional", it says nothing about it being rendered as a space if blank, which leads me to believe that it is rendered as a 0 if blank.

     

    If you want the user to be able to type in a number with no decimals then you should use

    ###,##0.99

    Based on the above interpretation of the masking element descriptions, this means that the user doesn't HAVE to type anything after the decimal, but in the text rendered, they will still see the "_.00" decimal places.

    Give it a shot anyhow.

     

    Also, I could be getting this completely wrong, so I would also attempt the following variations if that doesn't work:

    ###,##0.00
    999,999.00
    ###,###.00
    ###,###.##
    999,999.99


    Alain
  •  07-28-2010, 3:09 PM Post no. 27778 in reply to 27765

    Re: ValueToMaskedTextConverter

    Thanks for the reply. Sorry I should have mentioned all of the options I tried. ###,##0.00 results in 000,010.99.

    Test = Results

    0.00       =     ,   .    (if value is < 10 result is 9.99)
    ###,##0.00 =  000,010.99
    999,999.00 =  000,010.99
    ###,###.00 =  000,010.99
    ###,###.## =  000,010.99
    999,999.99 =  000,010.99

    I know it looks like it's not using my mask from the ConverterParameter but if I drop the comma it also drops from the display. It's as if all of the positions are never treated as optional regardless of the symbology used.

    Can someone from Xceed confirm this is the intended behavior? If so is there an alternate mask that will give me what I'm looking for?

    I'm using version 3.2 of the DataGrid.

    Thanks!

  •  07-30-2010, 11:07 AM Post no. 27823 in reply to 27778

    Re: ValueToMaskedTextConverter

    So I guess the answer is that this converter is broken and no one is going to fix it. Thanks.
  •  07-30-2010, 1:12 PM Post no. 27825 in reply to 27823

    Re: ValueToMaskedTextConverter

    And the solution is not to use the converter and use the StringFormat binding attribute instead. Xceed: you might want to update your documentation for the converter and indicate it's broken, deprecated, and to use StringFormat instead. Thanks for the dead-end.

    <sys:String x:Key="numericUnitsFormat">{0:n}</sys:String>

    <sys:String x:Key="currencyValueFormat">{0:c}</sys:String>

    <DataTemplate x:Key="currencyCellTemplate">

    <TextBlock Text="{Binding StringFormat={StaticResource numericUnitsFormat}}" />

    </DataTemplate>

    <DataTemplate x:Key="numericUnitsCellTemplate">

    <TextBlock Text="{Binding StringFormat={StaticResource currencyValueFormat}}" />

    </DataTemplate>

  •  07-30-2010, 2:38 PM Post no. 27827 in reply to 27825

    Re: ValueToMaskedTextConverter

    Hi Ken,

    We apologize for not posting a reply sooner. However, the StringFormat on the CellContentTemplate would have been our suggestion as well.

    As for your comments in regards to the documentation, I sent your feedback to the appropriate team and they will take a look at that page and update it as needed.

    * For faster support, I would suggest sending your requests by email instead.
      The general support email is support@xceed.com
      As a Vanguard subscriber, you can also use priority@xceed.com

     


    ** Quick Tip: Clients with an active support subscription should be sending their questions by email if they wish to benefit from the faster response time. Thanks!


    Diane Lafontaine
    Technical Support
    Xceed Software Inc.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.