简体   繁体   English

WPF ProgressBar不显示进度

[英]WPF ProgressBar doesn't show progress

I am confused by WPF ProgressBar. WPF ProgressBar使我感到困惑。 Here is the code I have written to display it: 这是我编写的用于显示它的代码:

<ProgressBar Height="31" Margin="15" Name="progressBar" 
VerticalAlignment="Top" IsIndeterminate="True" />

As I know this is enough to make it work. 据我所知,这足以使其正常工作。 But it doesn't work in my project. 但这在我的项目中不起作用。 I mean when I show window (Popup actually as it's xbap project) progressbar doesn't show any animation, however it is visible. 我的意思是,当我显示窗口(实际上是弹出窗口的xbap项目)时,进度条不显示任何动画,但是可见。

There are no background threads yet, UI thread is not blocked. 尚无后台线程,UI线程未被阻止。

What is wrong? 怎么了?

There are no background threads yet, UI thread is not blocked. 尚无后台线程,UI线程未被阻止。

I think you have that exactly wrong, and that's your problem. 我认为您完全错了,这就是您的问题。 You have no background threads, and thus your UI thread is blocked. 您没有后台线程,因此您的UI线程阻止。 If your method that updates the progress bar is running on the UI thread (which it is, if you're not running it on a background thread), updates to the progress bar won't appear until the method is done running and control is returned to the Dispatcher. 如果更新进度条的方法正在UI线程上运行(如果不是在后台线程上运行),则直到该方法完成运行并且控件已完成,才会显示进度条的更新。回到调度员。

You need to run your long-running method on a background thread using a BackgroundWorker , and update the progress bar by raising and handling its ProgressChanged event. 您需要使用BackgroundWorker在后台线程上运行长时间运行的方法,并通过引发和处理其ProgressChanged事件来更新进度栏。 The event handler runs on the UI thread, and can update UI objects. 事件处理程序在UI线程上运行,并且可以更新UI对象。

它可能使用Windows主题,其中不确定的进度条未正确显示。

Please try these codes 请尝试这些代码

        ProgressBar test=new ProgressBar();
        Duration dr = new Duration(TimeSpan.FromSeconds(timespan));
        DoubleAnimation da = new DoubleAnimation(determination, dr);
        test.IsIndeterminate = false;
        test.Visibility = Visibility.Visible;
        test.BeginAnimation(ProgressBar.ValueProperty, da);

If you want the ProgressBar work,you should create an Animation instance,and set it to the ProgressBar.May it help! 如果要ProgressBar工作,则应创建一个Animation实例,并将其设置为ProgressBar。可能有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM