什么事情都可以拖一拖,没必要那么着急,事缓则圆。努力去做自己该做的,但是不要期待回报,不是付出了就会有回报的,做了就不要后悔,不做才后悔。
本文实例为大家分享了WPF实现一个实时更新的进度条,供大家参考,具体内容如下
效果图
xaml代码
<Window x:Class="ProgressBar.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:ProgressBar" mc:Ignorable="d" Title="MainWindow" Height="250" Width="400"> <Grid> <ProgressBar Name="progressBar" Minimum="1" Maximum="1000" Height="50"/> <Button Content="Done" VerticalAlignment="Bottom" HorizontalAlignment="Center" FontSize="20" Margin="10" Click="Button_Click"/> </Grid> </Window>
后台代码
using System; using System.Windows; using System.Windows.Controls.Primitives; using System.Windows.Threading; namespace ProgressBar { /// <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) }); } } } }
本文WPF实现进度条实时更新效果到此结束。灿烂的犹如初开的太阳的面纱,灵秀的犹如崖边的一只百合,热情的犹如一株红色的玫瑰,散发着撩人的芬芳,她让我如此深深着迷。小编再次感谢大家对我们的支持!