BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
<Grid>
<syncfusion:DoubleTextBox x:Name="doubleTextBox" Width="100" Height="40"MinValue="1" MaxValue="50" ScrollInterval="0.5" NumberDecimalDigits="1" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
/// <summary>
/// Event triggers when value changed in the DoubleTextBox
/// </summary>
private void DoubleTextBox_ValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (doubleTextBox.Value != null)
{
int result = (int)((doubleTextBox.Value % 1) * 10);
if (result == 0)
{
doubleTextBox.NumberDecimalDigits = 0;
}
else
{
doubleTextBox.NumberDecimalDigits = 1;
}
}
} |
Query 1:
1. I can't type the decimal point, I have to scroll to increase it by .5 (it's not an acceptable behavior according to the users) |
As stated earlier, we do not have direct support to display the value as like in the provided example. So we have prepared the work around to achieve your requirement. In provided workaround, we have been changing NumberDecimalDigits in ValueChanged event as per your requirement. Due to this behavior, DoubleTextBox restrict the user to type decimal digit when NumberDecimalDigits property value is 0. To avoid this behavior we suggest you to remove the code which we provided in previous update. Please find the code snippet and sample for the same.
Code Snippet:
| |
Query 2:
2. If there's a point .5 on the number, you can still mess with the decimal number by placing the cursor at the end of the decimal number and typing any number you want.
|
Based on provided information, we suspect you want to restrict the cursor placed on the decimal number when there a point .5 on the number. If so, we cannot restrict the cursor placed on the decimal point.
If we misunderstood your requirement, please provide more information regarding the requirement with simple example. It would be more helpful to proceed further.
|
Query 1:
I can't remove the whole number without highlighting it, I can't click in front of the whole number and type in front of it to replace it. |
In DoubleTextBox, by default MaxValidation will occurs when key press on it. Since the Max Value is set as 50 in provided sample so it will not allow the user to type greater than 50. Please find the video for the same. If you want to avoid this behavior you can change MaxValidation property to MaxValidation.OnLostFocus. So that validation will occurs only on lost focus of the DoubleTextBox. Now you can click in front of whole number and replace it by another number.
Code Snippet:
| |
Query 2:
The decimal number accepts every number instead of only restricting it to 5. Is there any regex that would handle this instead? It seems the double text box's function is extremely limited.
|
Based on provided information, we suspect you want to restrict the decimal number accepts only 5(Eg 3.5). For this you need handle this case in ValueChanged event manually. Please confirm whether your expected behavior is same. Based on your confirmation we will proceed further on this. Currently DoubleTextBox does not have any regex.
|
this.doubleTextBox.TextChanged += DoubleTextBox_TextChanged;
}
private void DoubleTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
doubleTextBox.Text = Convert.ToString((double)Math.Truncate((decimal)(doubleTextBox.Value)) + 0.5);
}
|