Skip to content
This repository was archived by the owner on Aug 27, 2020. It is now read-only.

NumericValidationBehavior

Mark Smith edited this page Sep 1, 2016 · 2 revisions

NumericValidationBehavior

The NumericValidationBehavior class is a custom Xamarin.Forms behavior which can be applied to an Entry control to restrict the input type to be numeric even with a free-form keyboard. Note that this behavior does not change the value of the Entry, it simply changes the visual text color to indicate that the input is not valid. True validation should be done in code behind or in a ViewModel.

Properties

  • AllowDecimal : When true, a decimal point is allowed (floating point), when false, only integer values are allowed. Defaults to true.
  • InvalidColor : Color to use for an invalid entry. Defaults to Color.Red.

Example

<Entry Text="{Binding Amount, Mode=TwoWay}">
   <Entry.Behaviors>
      <inf:NumericValidationBehavior AllowDecimal="true" InvalidColor="Orange" />
   </Entry.Behaviors>
</Entry>