使用wpf中的按钮启动和停止风扇图像? [英] start and stop a fan image with a button in wpf?

查看:402
本文介绍了使用wpf中的按钮启动和停止风扇图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些关于通过visual studio 2012中的启动和停止按钮来控制风扇图像的连续旋转的一些帮助wpf visual basic ...需要xaml代码和一些解释来理解这个过程。我会非常感谢

I need some help about controlling the continuous rotation of a fan image by the start and stop button in visual studio 2012 wpf visual basic...need xaml code and a bit explanation for understanding the process..i,ll be very thankful

推荐答案

像大多数问题一样,需要将其分解为组件。

表单将包含带有事件处理程序的按钮,这些按钮将调用启动和停止风扇图像的方法。

要考虑的真正问题是,如果风扇在主机窗体中连续旋转,整个应用程序将冻结,用户将无法执行任何操作否则。

这意味着粉丝图像需要在另一个线程中或由后台工作者控制。因此,有些选择是:



1.将后台工作程序添加到主窗体或自定义用户控件,并使用它来启动和停止连续循环。这个循环必须有一种方法可以被中断,例如,如果取消赞成,或者



2.使用线程。后台工作人员会为您完成所有这些操作并且更安全,因为从线程访问表单可能会导致异常。
Like most problems it needs to be broken down into components.
The form will have the buttons with event handlers which will call start and stop methods for the fan image.
The real issue to consider is, if the fan is made to rotate continuously in the host form the whole application will freeze and user will not be able to do anything else.
This means the fan image needs to be in another thread or controlled with a background worker. So, some choices are:

1. add Background Worker to main form or custom user control and use that to start and stop the continuous loop. this loop must have a way to be interrupted, e.g if CancellationPending, or

2. use threads. Background Worker does all this for you and it's safer because accessing a form from a thread can cause an exception.


这篇关于使用wpf中的按钮启动和停止风扇图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆