IAnimatedVisualSource2 接口

定义

可由其他对象(如 AnimatedIcon)使用的动画视觉对象。 扩展 IAnimatedVisualSource

public interface class IAnimatedVisualSource2 : IAnimatedVisualSource
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.XamlContract, 65536)]
/// [Windows.Foundation.Metadata.Guid(440095655, 43262, 22945, 181, 68, 67, 164, 217, 200, 30, 242)]
struct IAnimatedVisualSource2 : IAnimatedVisualSource
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.XamlContract), 65536)]
[Windows.Foundation.Metadata.Guid(440095655, 43262, 22945, 181, 68, 67, 164, 217, 200, 30, 242)]
public interface IAnimatedVisualSource2 : IAnimatedVisualSource
Public Interface IAnimatedVisualSource2
Implements IAnimatedVisualSource
派生
属性
实现

示例

此示例显示实现 IAnimatedVisualSource2 的对象并设置其动画:

void AddVisualAndShowStartAnimation(
    const winrt::Border& element,
    const& winrt::IAnimatedVisualSource2 source,
    const winrt::hstring& initialState,
    const winrt::hstring& steadyState,
    const winrt::Color& themeColor )
{
    winrt::IAnimatedVisual animatedVisual = source.TryCreateAnimatedIconVisual();

    // Find the playback positions in the animation of the two states
    auto const markers = source.Markers();
    auto const fromProgress = static_cast<float>(markers.Lookup(initialState));
    auto const toProgress = static_cast<float>(markers.Lookup(steadyState));

    // Set the theme color as the animated visual's foreground.
    source.SetColorProperty("Foreground", themeColor);

    // Helper that uses TryCreateAnimatedVisual to add the source to the XAML element tree.
    // See IAnimatedVisualSource.TryCreateAnimatedVisual for more information.
    AddVisualToElement(element, animatedVisual);

    // Helper to play an animation.
    // See IAnimatedVisual for more information.
    PlaySegment(animatedVisual.RootVisual(), fromProgress, toProgress);
}

注解

调用 IAnimatedVisualSource.TryCreateAnimatedVisual (Compositor, Object) 方法来检索 IAnimatedVisual 对象。 然后,可以使用它 IAnimatedVisual 来获取 Composition.Visual,该组件可以使用 ElementCompositionPreview 的方法添加到 XAML 元素树中。

属性

Markers

获取一个集合,该集合提供标记名称到动画中播放位置的映射。

方法

SetColorProperty(String, Color)

设置动画视觉对象的颜色。

TryCreateAnimatedVisual(Compositor, Object)

尝试创建动画视觉对象。

(继承自 IAnimatedVisualSource)

适用于