question

ShereifAwad-5223 avatar image
0 Votes"
ShereifAwad-5223 asked ·

how to force validation xamarin forms community toolkit multivalidation

how to force entry validation on button pressed MVVM model

 <Entry Grid.Column="0" 
     Placeholder="Width"
     Text="{Binding Width}" TextColor="Black" Keyboard="Numeric">
  <Entry.Behaviors>
      <xct:MultiValidationBehavior x:Name="WidthMultiValidation"
                                   IsValid="{Binding BindingContext.IsWidthValid, Source={x:Reference list}}"
                                   InvalidStyle="{StaticResource InvalidEntryStyle}"
                                         
                                   >
          <xct:NumericValidationBehavior MaximumDecimalPlaces="2" 
                                         xct:MultiValidationBehavior.Error="Maximum Decimal Places Reached"/>
          <xct:NumericValidationBehavior MinimumValue="1"  
                                         xct:MultiValidationBehavior.Error="Values can not be Zero"
                                          />
          <xct:CharactersValidationBehavior MinimumCharacterCount="1"
                                            CharacterType="Digit"
                                            xct:MultiValidationBehavior.Error="Values can not be empty"/>
      </xct:MultiValidationBehavior>
  </Entry.Behaviors>
 </Entry>

I tried use ForceValidationCommand

 ForceValidateCommand="{Binding BindingContext.SetBoxDimensionsCommand, Source={x:Reference list}}"

command action

 private void SetBoxDimensions(object parameter)
 {
  if (parameter != null && parameter is Panel panel)
  {
      if(IsWidthValid && IsLengthValid && IsCountValid)
          panel.EditMode = false;
  }
 }

then i set the Falgs to forcevalidationCOmmand

 <Entry.Behaviors>
  <xct:MultiValidationBehavior x:Name="WidthMultiValidation"
                               IsValid="{Binding BindingContext.IsWidthValid, Source={x:Reference list}}"
                               InvalidStyle="{StaticResource InvalidEntryStyle}"
                               ForceValidateCommand="{Binding BindingContext.SetBoxDimensionsCommand, Source={x:Reference list}}"
                               Flags="ForceMakeValidWhenFocused">
                               ........
 </Entry.Behaviors>


But no Luck





dotnet-xamarinformsdotnet-xamarinforms-xaml
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You can set x:Name to MultiValidationBehavior, and then call ForceValidate` method.

Or manually call ForceValidateCommand.Excute() in button clicking event;

0 Votes 0 ·

0 Answers