question

Angelru-4290 avatar image
0 Votes"
Angelru-4290 asked Angelru-4290 edited

CarouselView Validation

I have a CarouselView with multiple ContenViews as if it were a "step by step" form. I wonder how I could validate the content before the user swipes. Do I have to do everything in the CurrentItemChangedCommand?

dotnet-xamarin
· 1
5 |1600 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.

Yes , you could do the Validation in CurrentItemChangedCommand or CurrentItemChanged event , disable the swipe if the validate failed and enable it if validate passed.

0 Votes 0 ·

1 Answer

Angelru-4290 avatar image
0 Votes"
Angelru-4290 answered Angelru-4290 edited

I have:

 <CarouselView x:Name="CarouselRegister" Position="{Binding Position}" IndicatorView="indicatorView" 
                   Loop="False" 
                   IsSwipeEnabled="False">
         <CarouselView.ItemsSource>
             <x:Array Type="{x:Type ContentView}">
                 <views:CenterView />
                 <views:PersonalInformationView />
                 <views:AddressView />
             </x:Array>
         </CarouselView.ItemsSource>
         <CarouselView.ItemTemplate>
             <DataTemplate x:DataType="d:ContentView">
                 <ContentView Content="{Binding .}" />
             </DataTemplate>
         </CarouselView.ItemTemplate>
     </CarouselView>
     <StackLayout Orientation="Horizontal">
         <Button Text="{xct:Translate Back}" BackgroundColor="DarkOrange" Command="{Binding BackCommand}">
             <Button.Triggers>
                 <DataTrigger TargetType="Button" Binding="{Binding Position}" Value="0">
                     <Setter Property="IsEnabled" Value="False" />
                 </DataTrigger>
             </Button.Triggers>
         </Button>
         <IndicatorView x:Name="indicatorView"
                        IndicatorSize="14"
                        IndicatorsShape="Circle"
                        Padding="14"
                        IndicatorColor="LightGray"
                        SelectedIndicatorColor="{StaticResource Primary}"
                        HorizontalOptions="CenterAndExpand">
         </IndicatorView>
         <Button Text="{xct:Translate Next}" BackgroundColor="DarkGreen" Command="{Binding NextCommand}" />
     </StackLayout>

And:


  public ICommand NextCommand => new Command(Next);
    
     private void Next()
     {
         if (Position + 1 != 0)
         {
             Position++;
         }
     }
    
     public ICommand BackCommand => new Command(Back);
    
     private void Back()
     {
         if (Position != 0)
         {
             Position--;
         }
     }

In each ContentView, I must do a validation through Behavior with XamarinCommunityToolkit, but I don't know very well how to approach it, since each Behavior is independent in ContentView, any ideas with my example?






5 |1600 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.