Hi Infragistics,
We have a scenario where we would like to display a value of 0 as an empty string using the XamNumericInput
We've achieved this elsewhere by use of a converter.
So we attempted to use this converter in a XamNumericInput but it doesn't appear to be working.
The converters have been specified in a Style like so...
<Style x:Key="XamNumericInputContractNumber" TargetType="{x:Type ig:XamNumericInput}">
<Setter Property="Width" Value="80"/>
<Setter Property="ValueTypeName" Value="Int32"/>
<Setter Property="PromptChar" Value=""/>
<Setter Property="InvalidValueBehavior" Value="RevertValue"/>
<Setter Property="ValueConstraint">
<Setter.Value>
<ig:ValueConstraint ValidateAsType="Integer32" MinInclusive="0" MaxInclusive="2147483647"/>
</Setter.Value>
</Setter>
<Setter Property="ValueToTextConverter" Value="{pcWPF:ZeroIntegerToStringConverter}"/>
<Setter Property="ValueToDisplayTextConverter" Value="{pcWPF:ZeroIntegerToStringConverter}"/>
</Style>
The ValueToDisplayTextConverter appears to be working (when displaying) but not the ValueToTextConverter (when editing)
Please could you confirm this is a bug?
Is there another way to achieve this behaviour using either Mask, Format or FormatProvider?
Hello ifdef,
Thank you for your post!
I have been investigating into this behavior you are seeing, and I have reproduced it. As of yet, I have not come up with a solution for you, and I am currently looking into this with my colleagues to determine whether this is a bug in the XamNumericInput or not. I will have more information for you on this matter shortly.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Many thanks Andrew.
I have been investigating this with my team members, and this does not appear to be a bug. The ValueToTextConverter for the XamNumericInput is used in a couple of ways, but primarily it is used to get the Value for a given string, and it is used to get the string representation of that Value so that it can update the Text property of the input. This is just as the ValueToDisplayTextConverter does, just with the DisplayText property rather than the Text property. In other words, the ValueToTextConverter takes the string typed into the mask when editing and passes that to the ConvertBack method. Then it takes that result and updates the Value property, which updates the Text property.
If you were to return null or double.NaN from the ConvertBack method, know that it is only in the process of getting a "value" for the entered text and the result(what you return from ConvertBack) is pushed into the Value property. The mask will continue to show whatever text was typed in. This is why you are not seeing an empty value when re-entering edit mode on the control.
My recommendation for a workaround to this is to bind your XamNumericInput's Value property to a nullable type, such as double? or int?. Then, in the setter for this property, you could check if the value is equal to 0. If it is, then set that value to null. This will show up as blank in the XamNumericInput.
Thanks Andrew.
The documentation does state...
ValueToTextConverter is used when the editor is in edit mode where as ValueToDisplayTextConverter is used when the editor is not in edit mode.
When the numeric input gains focus (and hence enters edit mode) ValueToTextConverter is not called. That's the issue we're seeing.
The model property is a required value, so changing it to not-null is not an option. Zero is the default, we just don't want to show it, hence the converters.
I believe this behavior you are seeing is actually expected. The ValueToTextConverter is used in edit mode, but it will not be called when you initially enter edit mode and this is because the ValueToTextConverter and the ValueToDisplayTextConverter are set up to fire when the Value property of the XamNumericInput changes. When you enter edit mode, the value has not changed, and so the converter will not be called. You will notice though, that the converter will be called the moment that you begin typing while in edit mode.
I have been collaborating a bit further with my team members on this issue, and it does not appear that the XamNumericInput currently has any functionality for the control to maintain a Value but have its mask be cleared (Value = 0 and mask = null). If you would like to see this functionality implemented into the XamNumericInput control, I would suggest that you go to our product ideas site http://ideas.infragistics.com and add the feature that you would like to see as well as vote on other suggested features. This site puts you in touch with our product management team who plans and prioritizes new features based on customer input.