如何使用WPF进度栏?

编程入门 行业动态 更新时间:2024-10-27 09:42:46
本文介绍了如何使用WPF进度栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将IsIndeterminate属性设置为true的WPF进度条控件.我的问题是,它没有更新.

I am trying to use the WPF progressbar control with the IsIndeterminate property set to true. The problem I have, is that it doesn't get updated.

我正在做这样的事情:

pbProgressBar.Visibility = Visibility.Visible; //do time consuming stuff pbProgressBar.Visibility = Visibility.Hidden;

我试图将其包装在线程中,然后使用Dispatcher对象进行分派.我该如何解决这个问题:).

I tried to wrap this in a thread and then dispatch it with the Dispatcher object. How should I solve this problem :).

推荐答案

您必须在后台线程上执行耗时的工作,并且必须确保未将 Visibility 设置回隐藏,直到之后后台线程完成了它的工作.基本过程如下:

You must do the time consuming stuff on a background thread, and you must ensure that the Visibility isn't set back to Hidden until after the background thread has done its thing. The basic process is as follows:

private void _button_Click(object sender, RoutedEventArgs e) { _progressBar.Visibility = Visibility.Visible; new Thread((ThreadStart) delegate { //do time-consuming work here //then dispatch back to the UI thread to update the progress bar Dispatcher.Invoke((ThreadStart) delegate { _progressBar.Visibility = Visibility.Hidden; }); }).Start(); }

更多推荐

如何使用WPF进度栏?

本文发布于:2023-11-23 09:50:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621006.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   进度   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!