BitmapImage.IsAnimatedBitmap 屬性

定義

取得值,這個值表示影像是否為動畫。

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

屬性值

Boolean

bool

如果影像是動畫,則為true;否則為false

Windows 需求

裝置系列
Windows 10 Anniversary Edition (已於 10.0.14393.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v3.0 引進)

範例

此範例示範如何使用動畫 GIF。 按鈕可讓使用者啟動或停止動畫。 系統會檢查 IsAnimatedBitmap 屬性,以判斷按鈕是否顯示或隱藏。

此範例會使用版本調適型程式碼,以便在所有版本的 Windows 10 上執行。 在 1607 版之前的版本中,會顯示 GIF 的第一個畫面格,但不會以動畫顯示。

<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;
    }
}

備註

從 Windows 10 1607 版開始,XAML Image元素支援動畫 GIF 影像。 當您使用 BitmapImage 做為影像 來源時,您可以存取 BitmapImage API 來控制動畫 GIF 影像的播放。 如需詳細資訊,請參閱 BitmapImage 類別和 動畫 GIF 播放範例的一節。

相容性注意事項

如果您的應用程式在 1607 版之前的Windows 10版本上執行,您必須使用ApiInformation類別來檢查此屬性是否存在,才能使用它。 如需詳細資訊,請參閱 版本調適型程式碼:使用新的 API,同時維持與舊版的相容性

適用於