-
Notifications
You must be signed in to change notification settings - Fork 803
Closed
Labels
bugSomething isn't workingSomething isn't workingneeds-triageIssue needs to be triaged by the area ownersIssue needs to be triaged by the area owners
Description
Describe the bug
Animations for the Width and Height properties of a Rectangle do not work in WinUI 3. The animations are defined using DoubleAnimationUsingKeyFrames, but they do not have any effect on the Rectangle.
Steps to reproduce the bug
Steps to reproduce the bug
- Create a new WinUI 3 project targeting .NET 8.
- Add the following XAML to define a
Rectangleand aStoryboardto animate itsWidthandHeightproperties: - Add the following code-behind to start the animation:
WindowKeyframe.xaml
<?xml version="1.0" encoding="utf-8"?>
<Window
x:Class="WinUiLearn.WindowKeyFrame"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WinUiLearn"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="WindowKeyFrame">
<Grid>
<Grid.Resources>
<Storyboard x:Name="rectangleStoryboard">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="animatedRectangle" Storyboard.TargetProperty="(Canvas.Left)">
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
<LinearDoubleKeyFrame Value="300" KeyTime="0:0:2" />
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:4" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="animatedRectangle" Storyboard.TargetProperty="(Canvas.Top)">
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
<LinearDoubleKeyFrame Value="200" KeyTime="0:0:2" />
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:4" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="rectangleStoryboard2">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="animatedRectangle2" Storyboard.TargetProperty="Width">
<LinearDoubleKeyFrame Value="50" KeyTime="0:0:0" />
<LinearDoubleKeyFrame Value="300" KeyTime="0:0:2" />
<LinearDoubleKeyFrame Value="50" KeyTime="0:0:4" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="animatedRectangle2" Storyboard.TargetProperty="Height">
<LinearDoubleKeyFrame Value="50" KeyTime="0:0:0" />
<LinearDoubleKeyFrame Value="200" KeyTime="0:0:2" />
<LinearDoubleKeyFrame Value="50" KeyTime="0:0:4" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Grid.Resources>
<Canvas>
<Rectangle x:Name="animatedRectangle" Width="50" Height="50" Fill="Blue" />
<Rectangle x:Name="animatedRectangle2" Width="50" Height="50" Canvas.Left="50" Fill="Red" />
<Button Content="Start Animation" Click="StartAnimation_Click" Canvas.Left="120" Canvas.Top="10" Background="Purple" />
</Canvas>
</Grid>
</Window>WindowKeyframe.xaml.cs
using Microsoft.UI.Xaml;
using System.Diagnostics;
namespace WinUiLearn
{
public sealed partial class WindowKeyFrame : Window
{
public WindowKeyFrame()
{
InitializeComponent();
}
private void StartAnimation_Click(object sender, RoutedEventArgs e)
{
Debug.WriteLine("StartAnimation_Click called");
rectangleStoryboard.Begin();
rectangleStoryboard2.Begin();
}
}
}- Run the application and click the "Start Animation" button.
Expected behavior
Expected behavior
The Width and Height properties of the Rectangle should animate as defined in the Storyboard.
Actual behavior
The Width and Height properties of the Rectangle do not change.
Version Info
- WinUI 3: [version]
- .NET: 8.0
Additional context
Copy the code from the offical demo not work
How to: Animate the Size of a FrameworkElement
<Button Name="AnimatedWidthButton"
Canvas.Left="220" Canvas.Top="20"
Width="200" Height="150"
BorderBrush="Red" BorderThickness="5">
Click Me
<Button.Triggers>
<!-- Animate the button's Width property. -->
<EventTrigger RoutedEvent="Button.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="AnimatedWidthButton"
Storyboard.TargetProperty="(Button.Width)"
To="500" Duration="0:0:10" AutoReverse="True"
RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>Screenshots
NuGet package version
None
Windows version
No response
Additional context
dotnet list pakage
> FFmpeg.AutoGen 7.0.0 7.0.0
> Microsoft.Windows.SDK.BuildTools 10.0.26100.1742 10.0.26100.1742
> Microsoft.WindowsAppSDK 1.6.241114003 1.6.241114003
> Microsoft.Xaml.Behaviors.WinUI.Managed 2.0.9 2.0.9OS Name: Microsoft Windows 11 Pro
OS Version: 10.0.26100 N/A Build 26100
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingneeds-triageIssue needs to be triaged by the area ownersIssue needs to be triaged by the area owners
