Home Forums WPF controls Xceed DataGrid for WPF MaskedTextBox with decimals and leading zero fails

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #26460 |

    I am using the MaskedTextBox with a Decimal and am having two major problems.
    1) Leading zero in the binding data causes the mask parse to fail. Therefore my data does not display if my decimal has leading zeros.
    2) I want to use IDataErrorInfo to validate the data in the MaskedTextBox. How can I pass the value from the MaskedTextBox to the binding object even if the parse fails? The reason I want to do this is all my validation happens in IDataErrorInfo.

    Here is what I have.

    <xcdg:MaskedTextBox x:Name=”MTextBox” Width=”100″
    Mask=”99.99″
    QueryTextFromValue=”Number_QueryTextFromValue”
    QueryValueFromText=”Number_QueryValueFromText”
    ValueDataType=”{x:Type s:Decimal}”
    Text=”{Binding Path=Price, UpdateSourceTrigger=PropertyChanged}”
    />

    If my object that I am binding to has the price
    Decimal _price = 55.51M
    everything is fine. If my object has the price
    Decimal _price = 05.51M
    the text in the MaskedTextBox is blank.

    How can I support decimals with leading zeros? Ideally if my decimal was zero the MaskedTextBox would display 00.00. So I want to pad zeros.

    Imported from legacy forums. Posted by Scott (had 2720 views)

    Xceed Support
    Member
    Post count: 5658

    The solution to your first issue would be to bind the Value property to your ‘Price” instead of the Text property.

    However, since you’re using the QueryTextFromValue and QueryValueFromText, you are probably handling the conversion yourself, and depending of your code in those handlers, binding to Text instead of Value should work.

    Simply using the following as a test, I had no problem displaying leading zeros…

    Ie:

    <xcdg:MaskedTextBox x:Name=”MTextBox” Width=”100″
    Mask=”99.99″
    ValueDataType=”{x:Type s:Decimal}”
    Text=”05.51″

    Concerning your second issue, if Text is the property bound to your business object, then the IdataErrorInfo interface should be used as soon as the target tries to update the source, that is, if you set the ValidatesOnDataErrors property to True on the binding.

    If you bind to Value instead of Text, then you have to keep in mind that when the text cannot be parsed, the Value will be equal to your MaskedTextBox NullValue. Again, the IdataErrorInfo will be used if you set the ValidatesOnDataErrors property to True on the binding.

    If you still have the issue with leading zeros, I would suggest sending a sample application reproducing the issue to our technical support department.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 1103 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Jenny,

    Binding to Value instead of Text seemed to fix all my problems.

    Thanks very much…

    Scott

    Imported from legacy forums. Posted by Scott (had 4156 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.