This project has moved and is read-only. For the latest updates, please go here.

IntegerUpDown is setting the value to defaultvalue specified only when I click on some other control

Jun 29, 2015 at 12:15 PM
I have two xceed integer updown controls and a save button as shown below.

<extWPF:IntegerUpDown Name="iudExpectedRevenue" Text="{Binding ExpectedRevenue}" Minimum="1" Increment="1" Maximum="250" DisplayDefaultValueOnEmptyText="True" ClipValueToMinMax="True" DefaultValue="1" />

<extWPF:IntegerUpDown Name="iudExpectedPageValue" />

<Button Name="btnSave" Command="{Binding AddJobCommand}" />

If i delete the value from the first integerupdown and click on second integerupdown the value in the firstintegerupdown shows defaultvalue "1" which is correct.
If i delete the value from the first integerupdown and directly click on save the value will be shown as blank in the Control instead of defaultvalue "1".

This is happenening due to control built in property DisplayDefaultValueOnEmptyText="True" which is happening only when i click on other control.I want to ensure that the integerupdown shows correct value before user clicks on save.
Jun 29, 2015 at 1:49 PM
Edited Jun 29, 2015 at 5:23 PM

This is related to

The defaultValue should be set only when focus is placed on another control so that if someone is removing the "Text" of the IntegerUpDown to write a new value, we don't want the defaultValue to show up in the middle of the process.

Here's a small test :
 <Button Name="btnSave" 

private void btnSave_Click_1( object sender, RoutedEventArgs e )
      System.Diagnostics.Debug.WriteLine( "Saving iudExpectedRevenue at " + iudExpectedRevenue.Text );
When clicking on the Save Button, the defaultValue is set to "iudExpectedRevenue" IntegerUpDown and the Click Button callback shows that "iudExpectedRevenue" IntegerUpDown "Text" value is correct at 1 (the defaultValue). So the correct default value would be saved.
Jun 29, 2015 at 2:34 PM
Edited Jun 29, 2015 at 3:39 PM
Yes its saving the current value in my case.I dont have any issue with save.
But I manually deleted the value from integerupdown control and clicked on save.
I want the control to show the update default value "1" when i navigate away from that control.So user wil know what was saved.

I just want to know the event which is causing the integerupdown control to reset to its specified defaultvalue when user enters invalid data.
In short I want to know the event which is setting iudExpectedRevenue.Text =1 after I removed the text from the control.
Jun 30, 2015 at 2:42 PM

The event that triggers a set to defaultValue of an integerUpDown when "Empty" is the "Text" value is :
where "TextBox" is the WatermarkTextBox included in the template of a NumericUpDown control.

In other word, when the focus shift away from the IntegerUpDown, it will sync the "Text" and "Value" property : in this case to the "Default" Value, via the "ComitInput()" method.

What you could do is define your own IntegerUpDown and call "ComitInput()" when mouse leaves the control :
 public class MyIntegerUpDown : IntegerUpDown
    public MyIntegerUpDown()
      Mouse.AddMouseLeaveHandler( this, OnMouseLeave );

    private void OnMouseLeave( object sender, MouseEventArgs e )
Jul 3, 2015 at 1:29 PM
<extWPF:IntegerUpDown x:Name="iudExpectedPageValue" MinWidth="70" Text="{Binding ExpectedPageVolume, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxWidth="284" Width="284" Margin="0,3,0,7" Height="20" Minimum="1000" DisplayDefaultValueOnEmptyText="True" ClipValueToMinMax="True" Increment="1000" Maximum="99999999" DefaultValue="1000" Value="1000" VerticalAlignment="Center">
                            <i:EventTrigger EventName="InputValidationError">
                                <i:InvokeCommandAction Command="{Binding Path=ValidationCommand}"/>
InputValidationError Event is never fired.However if i change it to MouseLeave or something else its working.

I want to do some changes when there is an input validation error like setting the tooltip and showing errortemplate and disabling save button.

I want to bind the event to my viewmodel so that i can do the changes.