当WPF进度条中的Indeterminate ="True"时,如何显示进度?

use*_*349 13 wpf wpf-controls

这必须是所有问题中最简单的问题,但我似乎无法弄明白.我有进度条,如何让它显示进度.我该如何开始呢?

<ProgressBar x:Name="ProgressUpload" Margin="5" IsIndeterminate="True" ></ProgressBar>
Run Code Online (Sandbox Code Playgroud)

Mau*_*lli 22

如果将IsIndeterminate设置为True,则进度具有某些内容正在进行但您无法确定确切持续时间的含义.因此,我只能告诉您将其设置为false并在其"标准"行为中使用进度条.

  • 我正在寻找的技巧是我必须设置最小值和最大值以及高度.一旦我设置它们就会显示出来. (10认同)

dys*_*oko 16

简单地说,如果您尝试使进度条开始,但作为一个不确定的条,那么您必须在准备好时将属性IsIndeterminate设置为true,并在完成时将其设置为false.

换句话说:

pbar.IsIndeterminate = true; //This starts your bar's animation
pbar.IsIndeterminate = false; //This stops your bar's animation
Run Code Online (Sandbox Code Playgroud)

为了给你提供你想要这样做的上下文,请看下面的psuedo代码:

//Some method that is going to start something that is going to take a while
public void StartLongRunningProcess()
{
    //Make a call to a web service asynchronously etc...

    //Start the animation for your progress bar
    pbar.IsIndeterminate = true;
}

//The method (delegate) that handles the result, usually from an event.
//This method will handle the result of the asynchronous call 
public void HandlerForLongRunningProcess()
{
    //Do stuff with result from your asynchronous web service call etc...

    //Stop the animation for your progress bar
    pbar.IsIndeterminate = false;
}
Run Code Online (Sandbox Code Playgroud)

让我第一个说我不确定这是否是这个属性的预期用法,但我可以说它绝对有效.