WPF 中更新 GUI 的方法
我想问什么方法更新 GUI 更适合我的场景。 我想根据用户触摸的输入从一个点到另一个点操纵(移动)多个控件。
我知道一些不同的方法来做到这一点。 调度员定时器和计时器。 (他们有什么区别?) 后台工作者。 故事板和开始动画方法。
就内存和资源节省以及编码更简单而言,通常建议使用以下哪种方法?
谢谢你!
I would like to ask what method to update GUI is better for my scenario.
I would like to manipulate (move) multiple controls from point to point based on the input from user's touches.
I know a few difference way to do it.
Dispatcher Timer & Timer. (What's the difference between them?)
BackgroundWorker.
Storyboard & BeginAnimation Method.
Which of these method is generally recommended to use in term of memory and resource saving and simpler to code?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想这 3 个 SO QA 应该可以帮助您理解所有差异:
DispatcherTimer 与 WPF 应用程序中用于任务计划程序的常规计时器
比较 Timer 与 DispatcherTimer
WPF BackgroundWorker 与 Dispatcher
I suppose these 3 SO QA should help u understand all the differences:
DispatcherTimer vs a regular Timer in WPF app for a task scheduler
Comparing Timer with DispatcherTimer
WPF BackgroundWorker vs. Dispatcher
除了 Vijay 给出的链接之外,在操作视觉效果时,WPF 应用程序中至关重要的一个常见概念是 Dispatcher
简而言之,Dispatcher 是 UI 的消息队列网关管理器,它接收委托并优先考虑它们在给定线程上执行。在WPF中,UI线程是STA。此外,在 UI 线程上创建的任何视觉效果都具有线程关联性,这意味着如果您正在执行任何多线程功能(为了更快的性能),那么在操作这些视觉效果时,例如更新它们的值、增加/减小它们的大小、聚焦它们、转换它们等必须使用 UI 调度程序来完成。
现在回到您的情况,当您想要移动项目时, 平移变换动画是一个不错的选择。
希望这可以帮助您朝着正确的方向前进。
Apart from the link given by Vijay, a common concept that is vital in WPF application while you manipulate visuals is Dispatcher
In short, a Dispatcher is a message queue gateway manager to the UI, that receives delegates and prioritises them to execute on the given thread. In WPF, UI thread is STA. Also any visual created on UI thread has a thread affinity which means if you are performing any multi threaded functionality (for faster performance) then when it comes to manipulating those visuals such as updating their values, increasing / deacresing their size, focusing them, transforming them etc. has to be done using the UI Dispatcher.
Now back to your situation, when you want to move items, translate transform animation is a good option.
Hope this helps you in correct direction.