HypernovaDesktop Components · docs
Binarymission
WPF › Slide Show › BinarySlideShow

BinarySlideShow

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WPF.Controls.InteractionControls

A slide show: shows a list of slides one after another, on a timer or under your control, with any of twenty-three transition effects between them – for kiosks, product tours, photo galleries, dashboards that cycle through views, and presentations.

public class BinarySlideShow : ContentControl

Inherits from / implements: ContentControl

Remarks

Slides

Each slide is a BinarySlideShowItem holding any content. Add them to Slides, which every slide show starts with, empty. To show a single slide of your own choosing, set SlideContent or call PlayThisSlide.

Playing

Play starts the timer, which shows the next slide every SlideTransitionTimerInterval milliseconds, going back to the first after the last; the first slide appears one interval after the start. Pause, Resume and Stop control the timer, and StartSlideShowOnceInstantiated plays without a call. The timer runs only while the control is on screen, so a slide show on a page the user has left stops by itself and carries on when the page is shown again.

Moving by hand

Next, Previous, GoToFirstSlide, GoToLastSlide and GoToThisSlide move through the slides – from buttons, or the arrow keys. Each action raises an AboutTo... event first, such as AboutToGoToNextSlide; set CancelEventArgs.Cancel in it to stop the action.

Caution

Next, Previous, GoToFirstSlide and GoToLastSlide pass the slide they move to as the outgoing side of the transition, so with the SlideTransitionEffect.Default, Slide and SlideFromBottom effects the slide shown changes to it only at the following move or timer tick. GoToThisSlide and the timer show the new slide at once.

Effects

SlideTransitionEffect chooses the transition, and can be changed between slides. Several effects use the control's own UIElement.Effect, UIElement.RenderTransform, UIElement.OpacityMask or template, so leave those to the control.

Examples

A self-running kiosk show with a fade every five seconds, and buttons to move by hand.

<Window x:Class="Kiosk.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:show="clr-namespace:Binarymission.WPF.Controls.InteractionControls;assembly=Binarymission.WPF.Controls.InteractionControls.SlideShow"
        Title="Welcome" Width="1024" Height="640">
    <DockPanel>
        <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Center">
            <Button Content="Previous" Margin="4" Click="OnPrevious" />
            <Button Content="Next" Margin="4" Click="OnNext" />
        </StackPanel>
        <show:BinarySlideShow x:Name="Tour" SlideTransitionEffect="Fade"
                              SlideTransitionTimerInterval="5000" StartSlideShowOnceInstantiated="True" />
    </DockPanel>
</Window>
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Binarymission.WPF.Controls.InteractionControls;

foreach (string file in new[] { "lobby.jpg", "showroom.jpg", "workshop.jpg" })
{
    Tour.Slides.Add(new BinarySlideShowItem
    {
        Content = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/Slides/" + file)), Stretch = Stretch.Uniform }
    });
}
Tour.AboutToGoToNextSlide += (sender, e) => e.Cancel = Tour.Slides.Count == 0;

private void OnNext(object sender, RoutedEventArgs e) { Tour.Next(); }
private void OnPrevious(object sender, RoutedEventArgs e) { Tour.Previous(); }

Members at a glance

Constructors
BinarySlideShowInitializes a new instance of the BinarySlideShow class.
Properties
BlendEffectStartColorGets or sets the first colour the SlideTransitionEffect.ColorBlend effect tints the slide with.
BlendEffectTransitionColorGets or sets the second colour the SlideTransitionEffect.ColorBlend effect tints the slide with.
DefaultSlideContentGets or sets the slide shown before the first slide, and used as the outgoing side of a transition when there is no slide before it.
DefaultSlideContentTextGets or sets the text of the built-in blank slide shown before the first slide.
IsPausedGets or sets whether the slide show is paused. Setting it calls Pause or Resume.
IsShowDefaultBlankSlideAtStartupGets or sets whether DefaultSlideContent is shown while the slide show waits for its first slide.
IsStoppedGets or sets whether the slide show is stopped. Setting it calls Stop or Play.
SlideContentGets or sets the slide on screen; setting it shows that content with the transition effect.
SlideTransitionEffectGets or sets the effect used to move from one slide to the next.
SlideTransitionTimerIntervalGets or sets how long each slide stays on screen while the slide show plays.
SlidesGets or sets the slides, in the order they are shown.
StartSlideShowOnceInstantiatedGets or sets whether the slide show plays by itself, with no call to Play.
Methods
GoToFirstSlideMoves to the first slide in Slides.
GoToLastSlideMoves to the last slide in Slides; the timer, if playing, goes on to the first.
GoToThisSlideShows the slide at a given position, and optionally plays on from it.
NextMoves on one slide; after the last, goes back to the first.
OnApplyTemplateShows the blank opening slide if IsShowDefaultBlankSlideAtStartup is on, and plays if StartSlideShowOnceInstantiated is on, whenever a template is applied.
PausePauses the slide show on the slide on screen, until Resume is called.
PlayStarts the slide show: the next slide is shown every SlideTransitionTimerInterval milliseconds, from the first again after the last.
PlayThisSlideShows a given slide, with the current transition effect, whether or not it is in Slides.
PreviousMoves back one slide; at the first slide, stays there.
ResumeCarries on a paused or stopped slide show from where it was.
StopStops the slide show; the slide on screen stays there. Play starts it again.
Events
AboutToGoToASpecificSlideIndexOccurs when GoToThisSlide is called, before the move; set Cancel to stay put.
AboutToGoToFirstSlideOccurs when GoToFirstSlide is called, before the move; set Cancel to stay on the slide.
AboutToGoToLastSlideOccurs when GoToLastSlide is called, before the move; set Cancel to stay on the slide.
AboutToGoToNextSlideOccurs when Next is called, before the move; set Cancel to stay on the slide.
AboutToGoToPreviousSlideOccurs when Previous is called, before the move; set Cancel to stay on the slide.
AboutToGoToSpecificSlideInstanceOccurs when PlayThisSlide is called, before the slide is shown; set Cancel to stop it.
AboutToPauseOccurs when Pause is called, before the slide show pauses; set Cancel to keep it playing.
AboutToPlayOccurs when Play is called, before the slide show starts; set Cancel to stop it starting.
AboutToResumeOccurs when Resume is called, before the slide show resumes; set Cancel to keep it paused.
AboutToStopOccurs when Stop is called, before the slide show stops; set Cancel to keep it playing.
Fields
BlendEffectStartColorPropertyIdentifies the BlendEffectStartColor dependency property.
BlendEffectTransitionColorPropertyIdentifies the BlendEffectTransitionColor dependency property.
DefaultSlideContentPropertyIdentifies the DefaultSlideContent dependency property.
DefaultSlideContentTextPropertyIdentifies the DefaultSlideContentText dependency property.
IsShowDefaultBlankSlideAtStartupPropertyIdentifies the IsShowDefaultBlankSlideAtStartup dependency property.
SlideContentPropertyIdentifies the SlideContent dependency property.
SlideTransitionEffectPropertyIdentifies the SlideTransitionEffect dependency property.
SlideTransitionTimerIntervalPropertyIdentifies the SlideTransitionTimerInterval dependency property.
SlidesPropertyIdentifies the Slides dependency property.
StartSlideShowOnceInstantiatedPropertyIdentifies the StartSlideShowOnceInstantiated dependency property.

Constructors

BinarySlideShow

public BinarySlideShow()

Initializes a new instance of the BinarySlideShow class.

Properties

BlendEffectStartColor

public Color BlendEffectStartColor

Gets or sets the first colour the SlideTransitionEffect.ColorBlend effect tints the slide with.

Value
The default is Colors.Gray. Applied faintly; its own alpha is not used.

BlendEffectTransitionColor

public Color BlendEffectTransitionColor

Gets or sets the second colour the SlideTransitionEffect.ColorBlend effect tints the slide with.

Value
The default is Colors.Blue. Applied very faintly; its own alpha is not used.

DefaultSlideContent

public object DefaultSlideContent

Gets or sets the slide shown before the first slide, and used as the outgoing side of a transition when there is no slide before it.

Value
The default is a blank slide in the window colour with DefaultSlideContentText centred on it.
Remarks

Shown at start-up only while IsShowDefaultBlankSlideAtStartup is on, and then only if it is a BinarySlideShowItem.

DefaultSlideContentText

public string DefaultSlideContentText

Gets or sets the text of the built-in blank slide shown before the first slide.

Value
The default is "Slideshow is initializing... please wait...".
Remarks

The built-in slide is made when the control is created, with the text this property has at that moment, so a value set afterwards does not reach it. To show text of your own, set DefaultSlideContent to a slide of your own.

IsPaused

public bool IsPaused

Gets or sets whether the slide show is paused. Setting it calls Pause or Resume.

Value
The default is false. Next and the other moves set it too.

IsShowDefaultBlankSlideAtStartup

public bool IsShowDefaultBlankSlideAtStartup

Gets or sets whether DefaultSlideContent is shown while the slide show waits for its first slide.

Value
true to show it. The default is false: the control is blank until the first slide.

IsStopped

public bool IsStopped

Gets or sets whether the slide show is stopped. Setting it calls Stop or Play.

Value
The default is false.

SlideContent

public object SlideContent

Gets or sets the slide on screen; setting it shows that content with the transition effect.

Value
The default is null. Each move and tick sets it to the slide shown.

SlideTransitionEffect

public SlideTransitionEffect SlideTransitionEffect

Gets or sets the effect used to move from one slide to the next.

Value
The default is SlideTransitionEffect.Default: no effect.
Remarks

Read at each transition, so it can be changed between slides – picked at random for variety, for example.

SlideTransitionTimerInterval

public double SlideTransitionTimerInterval

Gets or sets how long each slide stays on screen while the slide show plays.

Value
A time in milliseconds. The default is 3000 (three seconds).
Remarks

A change applies from the next tick. Allow for the effect's own length, up to three seconds. A negative value throws an ArgumentOutOfRangeException.

Slides

public List<BinarySlideShowItem> Slides

Gets or sets the slides, in the order they are shown.

Value
Each control starts with an empty list of its own, ready to add to.
Remarks

The list is read at every move and tick, so slides can be added while the show plays. Set to null, the timer shows SlideContent instead.

StartSlideShowOnceInstantiated

public bool StartSlideShowOnceInstantiated

Gets or sets whether the slide show plays by itself, with no call to Play.

Value
true to play. The default is false.
Remarks

Setting it to true calls Play at once (raising AboutToPlay), and again when the template is applied; the slides start once the control is on screen.

Methods

GoToFirstSlide

public void GoToFirstSlide()

Moves to the first slide in Slides.

Remarks

Raises AboutToGoToFirstSlide first. Does nothing while there are no slides.

GoToLastSlide

public void GoToLastSlide()

Moves to the last slide in Slides; the timer, if playing, goes on to the first.

Remarks

Raises AboutToGoToLastSlide first. Does nothing while there are no slides.

GoToThisSlide

public void GoToThisSlide(int slideIndex, bool startPlayingFromTheDesiredIndex)

Shows the slide at a given position, and optionally plays on from it.

Parameters
slideIndex
The zero-based position of the slide in Slides. A position past the last slide does nothing; a negative one throws.
startPlayingFromTheDesiredIndex
true to call Play after showing the slide; false to leave the slide show as it is.
Exceptions
ArgumentOutOfRangeException
slideIndex is negative and there are slides.
Remarks
Example
// Jump to the slide picked in a thumbnail strip, and play on from it.
Tour.GoToThisSlide(thumbnails.SelectedIndex, true);

Next

public void Next()

Moves on one slide; after the last, goes back to the first.

Remarks

Raises AboutToGoToNextSlide first. It sets IsPaused but does not stop the timer, which carries on from the new position.

OnApplyTemplate

public override void OnApplyTemplate()

Shows the blank opening slide if IsShowDefaultBlankSlideAtStartup is on, and plays if StartSlideShowOnceInstantiated is on, whenever a template is applied.

Remarks

Most effects switch the control's template as they run, so this is called again at those transitions, with the same results.

Pause

public void Pause()

Pauses the slide show on the slide on screen, until Resume is called.

Remarks

Raises AboutToPause first.

Play

public void Play()

Starts the slide show: the next slide is shown every SlideTransitionTimerInterval milliseconds, from the first again after the last.

Remarks

Raises AboutToPlay first. The first slide appears one interval after the call, and nothing advances until the control is on screen.

PlayThisSlide

public void PlayThisSlide(BinarySlideShowItem slide)

Shows a given slide, with the current transition effect, whether or not it is in Slides.

Parameters
slide
The slide to show. null does nothing.
Remarks

Raises AboutToGoToSpecificSlideInstance first. The timer, if playing, carries on from its own position at the next tick.

Previous

public void Previous()

Moves back one slide; at the first slide, stays there.

Remarks

Raises AboutToGoToPreviousSlide first. It sets IsPaused but does not stop the timer, which carries on from the new position.

Resume

public void Resume()

Carries on a paused or stopped slide show from where it was.

Remarks

Raises AboutToResume first.

Stop

public void Stop()

Stops the slide show; the slide on screen stays there. Play starts it again.

Remarks

Raises AboutToStop first.

Events

AboutToGoToASpecificSlideIndex

public event EventHandler<SlideShowEventArgs> AboutToGoToASpecificSlideIndex

Occurs when GoToThisSlide is called, before the move; set Cancel to stay put.

AboutToGoToFirstSlide

public event EventHandler<SlideShowEventArgs> AboutToGoToFirstSlide

Occurs when GoToFirstSlide is called, before the move; set Cancel to stay on the slide.

AboutToGoToLastSlide

public event EventHandler<SlideShowEventArgs> AboutToGoToLastSlide

Occurs when GoToLastSlide is called, before the move; set Cancel to stay on the slide.

AboutToGoToNextSlide

public event EventHandler<SlideShowEventArgs> AboutToGoToNextSlide

Occurs when Next is called, before the move; set Cancel to stay on the slide.

AboutToGoToPreviousSlide

public event EventHandler<SlideShowEventArgs> AboutToGoToPreviousSlide

Occurs when Previous is called, before the move; set Cancel to stay on the slide.

AboutToGoToSpecificSlideInstance

public event EventHandler<SlideShowEventArgs> AboutToGoToSpecificSlideInstance

Occurs when PlayThisSlide is called, before the slide is shown; set Cancel to stop it.

AboutToPause

public event EventHandler<SlideShowEventArgs> AboutToPause

Occurs when Pause is called, before the slide show pauses; set Cancel to keep it playing.

AboutToPlay

public event EventHandler<SlideShowEventArgs> AboutToPlay

Occurs when Play is called, before the slide show starts; set Cancel to stop it starting.

AboutToResume

public event EventHandler<SlideShowEventArgs> AboutToResume

Occurs when Resume is called, before the slide show resumes; set Cancel to keep it paused.

AboutToStop

public event EventHandler<SlideShowEventArgs> AboutToStop

Occurs when Stop is called, before the slide show stops; set Cancel to keep it playing.

Fields

BlendEffectStartColorProperty static

public static readonly DependencyProperty BlendEffectStartColorProperty

Identifies the BlendEffectStartColor dependency property.

BlendEffectTransitionColorProperty static

public static readonly DependencyProperty BlendEffectTransitionColorProperty

Identifies the BlendEffectTransitionColor dependency property.

DefaultSlideContentProperty static

public static readonly DependencyProperty DefaultSlideContentProperty

Identifies the DefaultSlideContent dependency property.

DefaultSlideContentTextProperty static

public static readonly DependencyProperty DefaultSlideContentTextProperty

Identifies the DefaultSlideContentText dependency property.

IsShowDefaultBlankSlideAtStartupProperty static

public static readonly DependencyProperty IsShowDefaultBlankSlideAtStartupProperty

Identifies the IsShowDefaultBlankSlideAtStartup dependency property.

SlideContentProperty static

public static readonly DependencyProperty SlideContentProperty

Identifies the SlideContent dependency property.

SlideTransitionEffectProperty static

public static readonly DependencyProperty SlideTransitionEffectProperty

Identifies the SlideTransitionEffect dependency property.

SlideTransitionTimerIntervalProperty static

public static readonly DependencyProperty SlideTransitionTimerIntervalProperty = DependencyProperty.Register( "SlideTransitionTimerInterval", typeof(double), typeof(BinarySlideShow), new PropertyMetadata(3000d, (o, args)

Identifies the SlideTransitionTimerInterval dependency property.

SlidesProperty static

public static readonly DependencyProperty SlidesProperty

Identifies the Slides dependency property.

StartSlideShowOnceInstantiatedProperty static

public static readonly DependencyProperty StartSlideShowOnceInstantiatedProperty

Identifies the StartSlideShowOnceInstantiated dependency property.