2

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?

Nestor
  • 8,194
  • 7
  • 77
  • 156

1 Answers1

0

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!

taquion
  • 2,667
  • 2
  • 18
  • 29
  • Did you test it with the latest version of DevEx controls? It doesn't work in my case: when you press backspace or delete, it first shows "0.0 miles", and only clears after you press that key again. – Arthur Kazykhanov Oct 10 '17 at 16:56
  • Yes, that is the same behavior I got. Without AllowInput set to true it is not even possible to clear the textedit after that additional backspace though. If you do not want to use eventhandlers I am afraid it is the only way. See [this](https://documentation.devexpress.com/WPF/6947/Controls-and-Libraries/Data-Editors/Common-Features/Masked-Input/Null-Value-Input-in-Masks) – taquion Oct 10 '17 at 17:17
  • I think topic starter tried setting `AllowNullInput` to true. The problem seems to be the `EditValueType="{x:Type sys:Double}"` part. Since it's impossible (as far as I know) to put there something like `sys:NullableDouble`, using events does seem to be the only option. – Arthur Kazykhanov Oct 10 '17 at 17:27
  • I do not have enough information to know what the topic starter tried to do or not, I just tested the code provided and it does not allow null entries as he said. And I think the problem is not the x:Type, look [this](https://www.devexpress.com/Support/Center/Question/Details/Q483355/textedit-not-working-if-masktype-is-set-numeric-and-mask-is-set-to-n-and-editvalue-is). And if he does not want that additional backspace hit or to use Devexpress's provided shortcuts (Ctrl + D, Ctrl + 0), then I agree that events are the only option =) – taquion Oct 10 '17 at 17:37