WPF控件可见性和按钮单击生命周期 [英] WPF Control Visibility and Button Click Lifecycle

查看:91
本文介绍了WPF控件可见性和按钮单击生命周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使进度条可见,然后检查连接,然后使进度条隐藏.按照那个顺序!

How can I make the progessbar visible, then check the connection, then make the progressbar hidden. In that Order!

private void button_Click(...)
{
    progBar.Visibility = Visibility.Visible;
    CheckTheConnection();
    progBar.Visibility = Visibility.Hidden;
}

如果删除隐藏"属性,则将运行CheckConnection,然后progBar变为可见.这与我想要的相反.

If I remove the Hidden attribute, the CheckConnection runs then the progBar becomes visible. This is the opposite of what I want.

推荐答案

CheckConnection中的代码放入线程中,然后通过适当的机制显示/更新进度条(调用)
Put the code in CheckConnection into a thread, and then display/update the progressbar via appropriate mechanisms (Invoke).


根据您对John的答复,您似乎需要对如何使用WPF中的线程有基本的了解.这是一篇有关以下主题的好文章:

http://msdn.microsoft.com/en-us/magazine/cc163328.aspx [ ^ ]

请注意,跨线程访问成员并不那么复杂(尽管您需要小心).
Based on your reply to John, it seems you need to get a basic understanding on how to use threads from WPF. This is a good article on the topic:

http://msdn.microsoft.com/en-us/magazine/cc163328.aspx[^]

Notice how accessing members across the threads is not that complex (although you do need to be careful).


http://www.wpf100.com/html/5/2012-04/article-215.html


这篇关于WPF控件可见性和按钮单击生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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