c# - C# How to change width of border rapidly?
问题描述
I want to make slide in animation. I want to do it by increasing the border width. To visualize, I have a border that is behind an ellipse and to make it slide in I want to rapidly increase its width like shown in code.
while(Border.Width < 150)
{
Border.Width += 4;
System.Threading.Thread.Sleep(70);
}
The problem is that it wont increase width of border until the whole process is finished no matter if I stop the thread for 70ms or 1000ms.
解决方案
您的代码中的问题是您正在使用该 thread.sleep 阻塞 UI 线程,因此在您停止阻塞之前它无法执行任何操作。
您可以使您的父方法异步并使用:
await.Task.Delay(70);
而不是睡觉。
但是你真的应该研究动画。
推荐阅读
- docker - Snakemake:预装所有可执行文件的 Docker 映像
- huawei-mobile-services - HMS 奖励广告| 服务器端验证| 回调没有数据
- pytorch - 关于训练 MobileDet 的问题
- javascript - Youtube api响应不提供数据
- routes - 根据域在nuxt中设置根页面目录
- python - 如何检查号码是否与列表中的号码相同
- wordpress - 如何更改 Contact Form 7 中的表单操作?
- windows - Unable to SSH to a Windows machine using Ngrok
- react-native - React Native - 带有大中间按钮的 Tab.Navigator 未完全显示
- php - 无法在 CircleCi 中生成代码覆盖率