Aracılığıyla paylaş


ConnectedAnimationService Class

Definition

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

public ref class ConnectedAnimationService sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 196608)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class ConnectedAnimationService final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 196608)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class ConnectedAnimationService
Public NotInheritable Class ConnectedAnimationService
Inheritance
Object Platform::Object IInspectable ConnectedAnimationService
Attributes

Windows requirements

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

Examples

Tip

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

If you have the WinUI 2 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 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

See also