c# - 流体网格高度动画 UWP
问题描述
我必须创建一个网格高度的动画(这与麦克风的 db 数据一起,我随机模拟了数据的接收)。但是我创建的动画一点也不流畅。如何获得动画以制作带有四个彩色条的谷歌助手(谷歌播放应用程序)之类的示例(我的意思是作为流体动画)?
MainPage.xaml:
<Grid>
<Grid x:Name="ColorGrid" Background="Blue" Height="150" Width="40" CornerRadius="20"/>
</Grid>
MainPage.xaml.cs:
DispatcherTimer TimerHeight = new DispatcherTimer();
Storyboard storyboard1 = new Storyboard();
double AnimationTime = 50;
public MainPage()
{
this.InitializeComponent();
TimerHeight.Interval = TimeSpan.FromMilliseconds(50);
TimerHeight.Tick += TimerHeight_Tick;
TimerHeight.Start();
}
private void TimerHeight_Tick(object sender, object e)
{
double ActualHeight = GetRandomNumber(150,350);
//ColorGrid.Height = ActualHeight;
StartAnimation(ColorGrid, ActualHeight);
}
public double GetRandomNumber(double minimum, double maximum)
{
Random random = new Random();
return random.NextDouble() * (maximum - minimum) + minimum;
}
private void StartAnimation(Grid GridColor, double GridHight)
{
storyboard1 = new Storyboard();
var AnimationOne = new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(AnimationTime)), Value = GridHight, EasingFunction = new QuarticEase() { EasingMode = EasingMode.EaseOut } };
var AnimOne = new DoubleAnimationUsingKeyFrames();
AnimOne.EnableDependentAnimation = true;
AnimOne.KeyFrames.Add(AnimationOne);
Storyboard.SetTargetProperty(AnimOne, "(FrameworkElement.Height)");
Storyboard.SetTarget(AnimOne, GridColor);
storyboard1.Children.Add(AnimOne);
storyboard1.Begin();
}
虽然我使用了动画,但好像有镜头。如何获得流畅的动画?
提前致谢。
解决方案
您好,欢迎来到我们美丽的社区!
首先,您是否尝试过在没有所有 Visual Studio 调试系统的情况下运行该应用程序?因为它很重并且可能导致动画不流畅......我也曾经经历过。因此,首先要做的是部署您的应用程序,然后单击它来运行它,就好像它是从商店安装的一样。
其次...您不是要在这么几毫秒内制作太多动画吗?尝试设置TimeSpan
更长一点(例如1000),看看会发生什么......
推荐阅读
- c# - 将 UDP 输出添加到 log4net 附加程序
- java - VSCode Java 调试器抛出未知错误
- python - Tweepy 绑定方法 API.me
- docker - 大 IP 删除 tcp/ip 路由并阻止与 Docker 容器的通信
- python - Python - 检查字典中的所有键值对并转换为 int 或 float
- mysql - 选择列中具有最大值的行
- unix - 计算 unix 文件中的行数,不包括多个标题和尾部
- azure - Azure 函数绑定在本地工作,但不在门户中
- android - 在android中实现和警报和提醒的最佳实践是什么?
- sql - SQL | 如何对 3 个项目的分区组求和?