这应该是最简单的问题,但我似乎无法弄清楚。我已经放置了进度条。如何显示进度?我该如何启动它?
<ProgressBar x:Name="ProgressUpload" Margin="5" IsIndeterminate="True" ></ProgressBar>
这应该是最简单的问题,但我似乎无法弄清楚。我已经放置了进度条。如何显示进度?我该如何启动它?
<ProgressBar x:Name="ProgressUpload" Margin="5" IsIndeterminate="True" ></ProgressBar>
如果将IsIndeterminate设置为True,则进度意味着某些内容正在进行中,但你无法确定确切的持续时间。因此,我只能告诉你将其设置为false,并在进度条的“标准”行为中使用它。
简单来说,如果您想让进度条开始运行,但是作为一个不确定的进度条,那么当准备好时,必须将IsIndeterminate属性设置为true,在完成时将其设置为false。
换句话说:
pbar.IsIndeterminate = true; //This starts your bar's animation
pbar.IsIndeterminate = false; //This stops your bar's animation
为了让你明白为什么要这样做,请看以下伪代码:
//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;
}
我先说一下,我不确定这个属性的预期用法是什么,但我可以肯定地说它确实有效。
progressBar.Visibility = Visibility.Visible;
progressBar.Visibility = Visibility.Collapsed;
显然,在某些环境中,必须明确设置高度才能运行不确定的动画,而在其他环境中则不需要。
IsIndeterminate = 'False'
,然后在Window_Loaded
事件中设置:myProgressBar.IsIndeterminate = true;
<Grid Margin="10, 20">
<ProgressBar Name="pbStatus" BorderThickness="1" Foreground="Green"
Value="{x:Bind Path=XamlProductionViewModel.XamlCurrentProgress, Mode=OneWay}"
IsIndeterminate="{x:Bind Path=XamlProductionViewModel.XamlIsIndeterminate, Mode=OneWay}"
Visibility="{x:Bind Path=XamlProductionViewModel.XamlProgressVisibility, Converter={StaticResource booleanToVisibilityConverter}, Mode=OneWay}"
Height="30" Background="Aqua" Minimum="0" Maximum="100"/>
</Grid>
这与上面的@dyslexicanaboko没有实质性区别,但对于您可以控制的演示而言,这是快速且易于完成的:
在XAML中:
<Button Content="Start Process" HorizontalAlignment="Center" Click="StartAProcess"/>
<Button Content="Stop Process" HorizontalAlignment="Center" Click="StopAProcess"/>
<ProgressBar Name="pBar1" Height="20"/>
Public Sub StartAProcess()
pBar1.IsIndeterminate = True
End Sub
Public Sub StopAProcess()
pBar1.IsIndeterminate = False
End Sub
IsIndeterminate="True"
? - H H