Back to Devexpress

DxCarousel.SlideToItemAsync(Int32) Method

blazor-devexpress-dot-blazor-dot-dxcarousel-dot-slidetoitemasync-x28-system-dot-int32-x29.md

latest2.4 KB
Original Source

DxCarousel.SlideToItemAsync(Int32) Method

Navigates to the Carousel item with the specified index.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public Task SlideToItemAsync(
    int index
)

Parameters

NameTypeDescription
indexInt32

The Carousel item index.

|

Returns

TypeDescription
Task

The task that is completed when the specified Carousel item is activated.

|

Remarks

Call the SlideToItemAsync method to navigate to the Carousel item with the specified index programmatically.

The following code snippet navigates to the first item in the gallery on a custom button click:

razor
<DxCarousel Width="500px"
            Height="300px"
            @ref="carousel"
            Data="@GetCarouselData()"
            LoopNavigationEnabled="true"
            ImageSizeMode="CarouselImageSizeMode.FillAndCrop">
</DxCarousel>

<DxButton Text="First Item" Click="MoveToFirst" />

@code {
    DxCarousel carousel;

    async Task MoveToFirst (MouseEventArgs args) {
        await carousel.SlideToItemAsync(0);
    }
}
csharp
List<CarouselData> GetCarouselData() {
    List<CarouselData> result = new List<CarouselData>();
    result.Add(new CarouselData("../images/image1.jpg", "image 1"));
    result.Add(new CarouselData("../images/image2.jpg", "image 2"));
    result.Add(new CarouselData("../images/image3.jpg", "image 3"));
    result.Add(new CarouselData("../images/image4.jpg", "image 4"));

    return result;
}

public class CarouselData {
    public string Src { get; set; }
    public string Alt { get; set; }

    public CarouselData(string src, string alt) {
        Src = src;
        Alt = alt;
    }
}

See Also

DxCarousel Class

DxCarousel Members

DevExpress.Blazor Namespace