ConnectedAnimationService Class

Definition

Represents a service that provides properties and methods to display a ConnectedAnimation.

public ref class ConnectedAnimationService sealed
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Static(Microsoft.UI.Xaml.Media.Animation.IConnectedAnimationServiceStatics, 65536, "Microsoft.UI.Xaml.WinUIContract")]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.WebHostHidden]
class ConnectedAnimationService final
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Static(typeof(Microsoft.UI.Xaml.Media.Animation.IConnectedAnimationServiceStatics), 65536, "Microsoft.UI.Xaml.WinUIContract")]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.WebHostHidden]
public sealed class ConnectedAnimationService
Public NotInheritable Class ConnectedAnimationService
Inheritance
ConnectedAnimationService
Attributes
Windows.Foundation.Metadata.ContractVersionAttribute Windows.Foundation.Metadata.MarshalingBehaviorAttribute Windows.Foundation.Metadata.StaticAttribute Windows.Foundation.Metadata.ThreadingAttribute Windows.Foundation.Metadata.WebHostHiddenAttribute

Examples

Tip

For more info, design guidance, and code examples, see Connected animation.

If you have the XAML Controls Gallery app installed, click here to open the app and see Connected Animation in action.

This example shows how to animate an image between two pages during a navigation.

SourcePage.xaml/SourcePage.xaml.cs

<Image x:Name="SourceImage"
       Width="200"
       Height="200"
       Stretch="Fill"
       Source="Assets/StoreLogo.png" />
private void NavigateToDestinationPage()
{
    ConnectedAnimationService.GetForCurrentView().PrepareToAnimate("image", SourceImage);
    Frame.Navigate(typeof(DestinationPage));
}

DestinationPage.xaml/DestinationPage.xaml.cs

<Image x:Name="DestinationImage"
       Width="400"
       Height="400"
       Stretch="Fill"
       Source="Assets/StoreLogo.png" />
protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);

    ConnectedAnimation imageAnimation = 
        ConnectedAnimationService.GetForCurrentView().GetAnimation("image");
    if (imageAnimation != null)
    {
        imageAnimation.TryStart(DestinationImage);
    }
}

Remarks

To get an instance of ConnectedAnimationService, call the static GetForCurrentView method.

When you call PrepareToAnimate, you supply a key to associate with the newly created ConnectedAnimation returned by the method. You can later use this key to retrieve the same animation by calling GetAnimation. This lets you connect the animation between two different pages without having to manually pass the reference to the ConnectedAnimation object between pages.

See the [Connected animation sample](https://github.com/microsoft/WindowsCompositionSamples/tree/master/SampleGallery/Samples/SDK 14393/ConnectedAnimationSample) for a complete example of ConnectedAnimationService.

Properties

DefaultDuration

Gets or sets the default time that the animation runs.

DefaultEasingFunction

Gets or sets the default CompositionEasingFunction used by the animation.

Methods

GetAnimation(String)

Returns the animation with the specified key.

GetForCurrentView()

Returns an instance of ConnectedAnimationService for the current view.

PrepareToAnimate(String, UIElement)

Returns a connected animation that's associated with the specified key and source element.

Applies to