BitmapImage.AutoPlay Property

Definition

Gets or sets a value that indicates whether an animated image should play as soon as it loads.

public:
 property bool AutoPlay { bool get(); void set(bool value); };
bool AutoPlay();

void AutoPlay(bool value);
public bool AutoPlay { get; set; }
var boolean = bitmapImage.autoPlay;
bitmapImage.autoPlay = boolean;
Public Property AutoPlay As Boolean

Property Value

Boolean

bool

true if an animated image should play as soon as it loads; otherwise, false. The default is true.

Examples

This example shows how to use version adaptive code to use this property in an app that runs on all versions of Windows 10. On versions prior to version 1607, the first frame of the GIF is shown, but it is not animated.

<Image Loaded="Image_Loaded">
    <Image.Source>
        <BitmapImage x:Name="imageSource"
                     UriSource="Assets/example.gif"/>
    </Image.Source>
</Image>
// Set the AutoPlay property.
private void Image_Loaded(object sender, RoutedEventArgs e)
{
    if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Media.Imaging.BitmapImage", "AutoPlay") == true)
    {
        imageSource.AutoPlay = false;
    }
}

Remarks

Starting in Windows 10, version 1607, the XAML Image element supports animated GIF images. When you use a BitmapImage as the image Source, you can access BitmapImage API to control playback of the animated GIF image. For more info, see the 'Animated images' section of the BitmapImage class Remarks and the Animated GIF playback sample.

Use the AutoPlay property, which defaults to true, to specify whether or not an animated bitmap plays as soon as it loads.

Note

For most apps, we recommend that you set AutoPlay to false if UISettings.AnimationsEnabled is false, to support the accessibility needs of users. Do not do this if the content of the animated GIF is important for the usability of your app.

Compatibility notes

If your app runs on releases of Windows 10 prior to version 1607, you must set this property in code and use the ApiInformation class to check for the presence of this property before you use it. If you set this property in XAML, you will get a XAML compiler error. For more info, see Version adaptive code: Use new APIs while maintaining compatibility with previous versions.

Applies to