WPF 进度条的样式
作者:邱名涛
撰写时间:2019 年 7 月 28 日
前台:
<ProgressBar Name="progressBar" Minimum="1" Maximum="1000" Height="20" VerticalAlignment="Bottom"/>
<Button Content="Done" VerticalAlignment="Bottom" HorizontalAlignment="Center" FontSize="20" Margin="122,0,124,20" Click="Button_Click"/>
后台:
using System;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Threading;
namespace WpfApp1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private delegate void UpdateProgressBarDelegate(DependencyProperty dp, object value);
private void Button_Click(object sender, RoutedEventArgs e)
{
UpdateProgressBarDelegate updateProgressBaDelegate = new UpdateProgressBarDelegate(progressBar.SetValue);
for (int i = (int)progressBar.Minimum; i <= (int)progressBar.Maximum; i++)
{
Dispatcher.Invoke(updateProgressBaDelegate, DispatcherPriority.Background, new object[] { RangeBase.ValueProperty, Convert.ToDouble(i) });
}
}
}
}