WPF中轻量级处理动画资源?
我创建了一个类似于 Chrome 浏览器选项卡上看到的循环处理动画...我想在整个应用程序中使用它,因此决定将其作为资源...但是...我想知道什么是在我的应用程序中轻松使用此动画资源的最佳方法/实践...下面是我处理动画的 xaml 代码。 它应该用作 DataTemplate 还是 ControlTemplate?
<Grid>
<Grid.Resources>
<Storyboard x:Key="LoadingAnimation" RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(c:Arc.EndAngle)" Storyboard.TargetName="arc">
<EasingDoubleKeyFrame KeyTime="0" Value="90"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="-90"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.2" Value="-270"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(c:Arc.StartAngle)" Storyboard.TargetName="arc">
<EasingDoubleKeyFrame KeyTime="0" Value="-90"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="-270"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.2" Value="-450"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Grid.Resources>
<Grid.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource LoadingAnimation}"/>
</EventTrigger>
</Grid.Triggers>
<c:Arc x:Name="arcbackground" StartAngle="0" EndAngle="359.9" Stroke="#FFE0E0E0" StrokeThickness="8"/>
<c:Arc x:Name="arc" Stroke="{StaticResource BlueGradientBrush}" StrokeThickness="8"/>
I have created a circular processing animation similar to the one seen on the Chrome browser tab... i want to use it throughout my application and therefore decide to put it as a resource.. however.. i would like to know what is the best way/practice to use this animation resource easily in my app... below is the xaml code for my processing animation.
should it be used as a DataTemplate or ControlTemplate?
<Grid>
<Grid.Resources>
<Storyboard x:Key="LoadingAnimation" RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(c:Arc.EndAngle)" Storyboard.TargetName="arc">
<EasingDoubleKeyFrame KeyTime="0" Value="90"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="-90"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.2" Value="-270"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(c:Arc.StartAngle)" Storyboard.TargetName="arc">
<EasingDoubleKeyFrame KeyTime="0" Value="-90"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="-270"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.2" Value="-450"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Grid.Resources>
<Grid.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource LoadingAnimation}"/>
</EventTrigger>
</Grid.Triggers>
<c:Arc x:Name="arcbackground" StartAngle="0" EndAngle="359.9" Stroke="#FFE0E0E0" StrokeThickness="8"/>
<c:Arc x:Name="arc" Stroke="{StaticResource BlueGradientBrush}" StrokeThickness="8"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几天前我需要类似的东西。我将故事板和要动画的元素放在用户控件中。我添加了一个依赖属性,以便能够通过投标启动/停止动画。剩下的就是在应用程序中任何需要的地方使用用户控件。
我的 XAML 如下所示:
及其隐藏代码:
I needed something similar a couple of days ago. I put the storyboard and the elements to be animated in a user control. I added a dependency property to be able to start/stop the animation through biding. All that's left is to use the user control wherever you need it in your application.
My XAML looks like this:
And its code-behind: