脚本宝典收集整理的这篇文章主要介绍了WPF实现进度条实时更新效果,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
本文实例为大家分享了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实现进度条实时更新效果全部内容,希望文章能够帮你解决WPF实现进度条实时更新效果所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。