我发现很多同学把思维固话了,通常我们需要实现的进度条是
我在网上看到好多例子,但是都没有我的简单,他们不是重写ProcessBar就是使用模板,
可以将TextBlock提取出来啊,灵活一点单独绑定
然后一句代码Panel.ZIndex="1"就搞定了
<StackPanel>
<Button Content="执行耗时任务" Margin="20"
Command="{Binding ProgressCommand}"/>
<Grid >
<TextBlock Panel.ZIndex="1" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding ElementName=progressBar1, Path=Value, StringFormat={}{0:0}%}" ></TextBlock>
<ProgressBar Margin="50" x:Name="progressBar1" Width="300" Height="20"
Value="{Binding ProgressValue}" Minimum="0" Maximum="100" />
</Grid>
</StackPanel>
private async void ExecuteProgress()
{
for (int i = 0; i <= 100; i++)
{
// 模拟耗时操作
await Task.Delay(50); // 每50毫秒进度增加1
ProgressValue = i;
}
}
public ICommand ProgressCommand { get; set; }
标签:百分比,数字,进度条,int,private,WPF
From: https://www.cnblogs.com/guchen33/p/18281458