Back to Devexpress

DxCarousel.SlidePreviousAsync() Method

blazor-devexpress-dot-blazor-dot-dxcarousel-77bb294c.md

latest2.7 KB
Original Source

DxCarousel.SlidePreviousAsync() Method

Navigates to the previous Carousel item.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public Task SlidePreviousAsync()

Returns

TypeDescription
Task

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

|

Remarks

Call the SlidePreviousAsync method to navigate to the previous Carousel item in code. In case of the first item in the gallery, the method behavior depends on the LoopNavigationEnabled property value. If this property is set to true, the SlidePreviousAsync method navigates to the last item in the gallery. If false – the method does nothing.

Example

The following code snippet navigates between Carousel items on custom button clicks:

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

<DxButton IconCssClass="oi oi-arrow-left" Click="OnPreviousButtonClick" />
<DxButton IconCssClass="oi oi-arrow-right" Click="OnNextButtonClick" />

@code {
    DxCarousel carousel;

    async Task OnNextButtonClick(MouseEventArgs args) {
        await carousel.SlideNextAsync();
    }

    async Task OnPreviousButtonClick(MouseEventArgs args) {
        await carousel.SlidePreviousAsync();
    }
}
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