Hello.
When I use a mask "{}{number:1-2}.##" in XamMaskedEditor, I expect first symbol can be "1" or "2". But I can input "0" as first symbol.
How can I exclude "0" as first symbol?
{number:1-2} will create a 1 digit numeric section. The validation it performs is not a per keystroke validation as it is typed but a value validation when the mask characters are evaluated to construct and validate the value for the editor similar to how the ValueConstraint is only applied/evaluated against the value itself. So the behavior exhibited is expected. Since you seem to be trying to define the acceptable input for each character position then the alternative here would be to use a char section. e.g. {}{char:1:1-2}.##
Hello Michael,
Mask {number:1-2} mean interval between 1 and 2 according the documentation. It doesn`t allow 0 anyway.
It`s the bug.
Please correct the bug.
Hello Alexey,
The editors do not provide functionality to prevent specific number from being entered as decimals. With the value constraint that I provided you can also set the MinInclusive property to 1 so that the user can never insert a number lower than 1. But I'd imagine this isn't what you want. Unfortunately validation is performed when the control exits edit mode, not while the user is typing. And there is no mask to prevent typing zeros as decimals, but allow other numbers as decimals.
It's possible to remove any trailing zeros, but only after edit mode as a format.
You'd have to handle the ValueChanged event on the editor and inspect the NewValue and OldValue event arguments to determine when to perform extra validation and force exit edit mode on the user if they type a zero in the decimal.
Let me know if you have any questions.
I tried to apply the solution. But it still does not work. I can input "0" as before.
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="NumberCell" >
<Setter Property="Template" >
<Setter.Value >
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}" >
<presentationsEx:XamMaskedEditor Margin="16,8,8,8"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Style="{StaticResource XamMaskedEditorStyle}"
Height="32"
PadChar="_"
DisplayMode="IncludeBoth"
Mask="{}{number:1-2}.##"
Text="{Binding Path=DataItem.OrderNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
Width="40"
InvalidValueBehavior="RetainValue">
<presentationsEx:XamMaskedEditor.ValueConstraint>
<editors:ValueConstraint RegexPattern="^[1-2]\.\d{2}$" />
</presentationsEx:XamMaskedEditor.ValueConstraint>
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<i:InvokeCommandAction Command="{Binding Path=DataContext.CheckAllNumbersCommand, RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}}" CommandParameter="{Binding DataItem}" />
</i:EventTrigger>
<i:EventTrigger EventName="EditModeStarted">
<ie:CallMethodAction MethodName="NumberCell_EditModeStarted" TargetObject="{Binding Path=DataContext, RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}}" />
<i:EventTrigger EventName="LostFocus">
<ie:CallMethodAction MethodName="NumberCell_LostFocus" TargetObject="{Binding Path=DataContext, RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}}" />
</i:Interaction.Triggers>
</presentationsEx:XamMaskedEditor>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Thank you for contacting Infragistics. You may use a regular expression to exclude zeros from being inputted on the editor.
eg.
<igEditors:XamMaskEditor.ValueConstraint> <igEditors:ValueConstraint RegexPattern="^-?(0\.\d*[1-9]\d*|[1-9]\d*(\.\d+)?)$"/> </igEditors:XamMaskEditor.ValueConstraint>