Udostępnij za pośrednictwem


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.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
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.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class ConnectedAnimationService
Public NotInheritable Class ConnectedAnimationService
Inheritance
Object Platform::Object IInspectable ConnectedAnimationService
Attributes

Examples

Tip

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

The WinUI 3 Gallery app includes interactive examples of most WinUI 3 controls, features, and functionality. Get the app from the Microsoft Store or get the source code on GitHub.

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