Dela via


BitmapImage.Stop Method

Definition

Ends the animation of an animated image.

public:
 virtual void Stop() = Stop;
void Stop();
public void Stop();
function stop()
Public Sub Stop ()

Windows requirements

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

Examples

Here's how to use the ApiInformation.IsMethodPresent to check for the presence of the Stop method before you call it.

if (ApiInformation.IsMethodPresent("Windows.UI.Xaml.Media.Imaging.BitmapImage", "Stop"))
{
    imageSource.Stop();
}

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. In this case, the presence of the IsPlaying property indicates that the Play and Stop methods are also present, so an additional API check is not needed.

<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 method before you use it. For more info, see Version adaptive code: Use new APIs while maintaining compatibility with previous versions.

Applies to