Skip to main content
All docs
V24.2

DxCarousel.SlideShowDelay Property

Specifies the time interval between slide changes. Takes effect if the slide show functionality is enabled.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

[DefaultValue(2000)]
[Parameter]
public int SlideShowDelay { get; set; }

Property Value

Type Default Description
Int32 2000

The time interval in milliseconds.

Remarks

Set the SlideShowEnabled property to true to enable the slide show functionality in a <DxCarousel> component. To adjust the time interval between slide changes, use the SlideShowDelay property.

Example

The following code snippet changes Carousel slides automatically every 3 seconds (3,000 milliseconds):

<DxCarousel Width="500px"
            Height="300px"
            Data="@GetCarouselData()"
            LoopNavigationEnabled="true"
            ImageSizeMode="CarouselImageSizeMode.FillAndCrop"
            SlideShowEnabled="true"
            SlideShowDelay="3000">
</DxCarousel>

@code {
    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;
        }
    }
}

Task-Based Example

Set a Slide Show Delay for Individual Items

You may need to set a slide show delay for each carousel item individually. Follow the steps below to implement this functionality:

  1. Add an interger field (Delay) to your data source and define its values for each carousel item.
  2. Declare an interger property (CurrentDelay) and bind it to the SlideShowDelay property.
  3. Assign the first item’s Delay field value to the CurrentDelay property in the OnInitialized lifecycle method.
  4. Handle the ActiveItemIndexChanged event. In the handler, use the current item’s index to apply the corresponding slide show delay.
<DxCarousel @ref="carousel"
            Height="600px"
            Data="@carouselItems"
            ImageSrcField="ImageSource"
            ImageAltField="ImageAlt"
            SlideShowEnabled="true"
            SlideShowDelay="@CurrentDelay"
            LoopNavigationEnabled="true"
            ActiveItemIndexChanged="OnActiveItemIndexChanged">
</DxCarousel>

@code {
    int CurrentDelay { get; set; }
    DxCarousel carousel;

    protected override void OnInitialized() {
        base.OnInitialized();
        CurrentDelay = carouselItems.First().Delay;
    }
    async void OnActiveItemIndexChanged(int index) {
        if (index != null) {
            CurrentDelay = carouselItems.ElementAt(index).Delay;
        }
    }
    public class CarouselItem {
        public string ImageSource { get; set; }
        public string ImageAlt { get; set; }
        public int Delay { get; set; }
    }
    IEnumerable<CarouselItem> carouselItems = new List<CarouselItem>() {
        new CarouselItem{ImageSource="/images/image1.jpg", ImageAlt="Image 1", Delay=1000},
        new CarouselItem{ImageSource="/images/image2.jpg", ImageAlt="Image 2", Delay=3000},
        new CarouselItem{ImageSource="/images/image3.jpg", ImageAlt="Image 2", Delay=5000},
    };
}
See Also