Share via


BitmapImage.IsAnimatedBitmap Property

Definition

Gets a value that indicates whether an image is animated.

public:
 property bool IsAnimatedBitmap { bool get(); };
bool IsAnimatedBitmap();
public bool IsAnimatedBitmap { get; }
var boolean = bitmapImage.isAnimatedBitmap;
Public ReadOnly Property IsAnimatedBitmap As Boolean

Property Value

Boolean

bool

true if the image is animated; otherwise, false.

Examples

This example shows how to use an animated GIF. A button lets the user start or stop the animation. The IsAnimatedBitmap property is checked to determine whether the button is shown or hidden.

The example uses version adaptive code so it can run 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.

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Image>
        <Image.Source>
            <BitmapImage x:Name="imageSource"
                         UriSource="Assets/example.gif"
                         ImageOpened="imageSource_ImageOpened"/>
        </Image.Source>
    </Image>

    <AppBarButton x:Name="playButton"
              Icon="Play"
              Visibility="Collapsed"
              Click="playButton_Click"/>
</Grid>
// Show the play/stop button if the image is animated.
private void imageSource_ImageOpened(object sender, RoutedEventArgs e)
{
    var bitmapImage = (BitmapImage)sender;
    // At this point you can query whether the image is animated or not.
    if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Media.Imaging.BitmapImage", "IsAnimatedBitmap") 
        && bitmapImage.IsAnimatedBitmap == true)
    {
        // Enable the play button
        playButton.Visibility = Visibility.Visible;
    }
}

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.

Compatibility notes

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

Applies to