How to clear a masked TextEdit with Delete or BackSpace

Viewed 652

I have the following TextEdit, bound to a nullable field (Value1):

 <dxe:TextEdit EditValue="{Binding Path=Data.Value1, TargetNullValue={x:Null}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" EditValueType="{x:Type sys:Double}" Mask="##.# miles" />

When I hit BackSpace, it shows the remainig mask part (like this: . miles), and its EditValue is set to 0 in the background (which is wrong as it is bound to a nullable field)

I intend to make the EditValue to be null when BackSpace or Delete is used.

How can I do it without a converter or a KeyPress event handler?

1 Answers

This is in fact possible, all you need to do is to set AllowNullInput to true. You may want also to change your mask so that it does not show only the text . miles when you delete every value.

Here is my sample:

<Grid Background="DimGray">

        <dxe:TextEdit EditValue="{Binding Path=Value, TargetNullValue={x:Null}, 
            Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" 
                      MaskType="Numeric" 
                      EditValueType="{x:Type sys:Double}"
                      AllowNullInput="True"
                      Mask="#0.0 miles"
                      VerticalAlignment="Center"/>
    </Grid>

Hope this helps!

Related