Udostępnij za pośrednictwem


BitmapImage.IsPlaying Property

Definition

Gets a value that indicates whether an animated image is playing.

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

Property Value

Boolean

bool

true if the animated image is playing; otherwise, false.

Windows requirements

Device family
Windows 10 Anniversary Edition (introduced in 10.0.14393.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v3.0)

Examples

This example shows how to use an animated GIF. A button lets the user start or stop the animation. The IsPlaying property is checked to determine whether the Play or Stop method is called to toggle playback.

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"/>
        </Image.Source>
    </Image>

    <AppBarButton x:Name="playButton"
              Icon="Play"
              Click="playButton_Click"/>
</Grid>
// Play or stop the animated bitmap.
void playButton_Click(object sender, RoutedEventArgs e)
{
    if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Media.Imaging.BitmapImage", "IsPlaying") 
        && imageSource.IsPlaying == true)
    {
        playButton.Icon = new SymbolIcon(Symbol.Play);
        imageSource.Stop();
    }
    else
    {
        playButton.Icon = new SymbolIcon(Symbol.Stop);
        imageSource.Play();
    }   
}

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 IsPlaying property along with the Play and Stop methods to control the playback of an animated bitmap.

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