Search code examples
c#.netxamlcarouselmaui

There is a way to NOT center the first element on a Carrousel View using .NET Maui


I'm using a Carrousel View to display a images

There is the result :

enter image description here

This is fine but I want the first at the start of the screen like this :

enter image description here

There is the xaml :

<StackLayout>
   <CarouselView ItemsSource="{Binding Carte, Mode=TwoWay}" IndicatorView="indicatorView2" PeekAreaInsets="100" HeightRequest="200" >
      <CarouselView.ItemsLayout>
         <LinearItemsLayout Orientation="Horizontal" ItemSpacing="10" />
      </CarouselView.ItemsLayout>
      <CarouselView.ItemTemplate>
         <DataTemplate x:DataType="DTO:CategorieMenu">
            <StackLayout>
               <Image Source="{Binding ImgSource}" HeightRequest="150" HorizontalOptions="Center" />
               <Label Text="{Binding Name}" Style="{StaticResource MainPageLabelStyle}"/>
            </StackLayout>
         </DataTemplate>
      </CarouselView.ItemTemplate>
   </CarouselView>
</StackLayout>

I tried a lot of things but I can't find what to do. Did someone know how to do this ?


Solution

  • I found something to do what I want but I think a proper way exist :

    <CarouselView ItemsSource="{Binding Carte, Mode=TwoWay}" Margin="-170,0,0,0" IndicatorView="indicatorView2" PeekAreaInsets="180" HeightRequest="200" >
        <CarouselView.ItemsLayout>
            <LinearItemsLayout Orientation="Horizontal" />
        </CarouselView.ItemsLayout>
        <CarouselView.ItemTemplate>
            <DataTemplate x:DataType="DTO:CategorieMenu">
                <VerticalStackLayout >
                    <Image Source="{Binding ImgSource}" HeightRequest="150" HorizontalOptions="Center" />
                    <Label Text="{Binding Name}" Style="{StaticResource MainPageLabelStyle}" HorizontalOptions="Center"/>
                </VerticalStackLayout>
            </DataTemplate>
        </CarouselView.ItemTemplate>
    </CarouselView>