WPF ProgressBar实现实时进度效果

  

本文实例为大家分享了WPF ProgressBar实现实时进度的具体代码,供大家参考,具体内容如下
  

  

 WPF ProgressBar实现实时进度效果

  

简单测试,页面如图:

  

利用上班的一点点空闲时间,做了个wpf progressbar的例子,觉得有潜力可挖,故放上来供大家参考,有写的更好的请留言哦,方便交流学习,谢谢

  

这个xaml:

        & lt;页面x:类=" WpfBrowserAppDrill.ProgressBarPage "   xmlns=" http://schemas.microsoft.com/winfx/2006/xaml/presentation "   xmlns: x=" http://schemas.microsoft.com/winfx/2006/xaml "   xmlns: mc=" http://schemas.openxmlformats.org/markup-compatibility/2006 "   xmlns: d=" http://schemas.microsoft.com/expression/blend/2008 "   主持人:可忽略的=" d "   Title=癙rogressBarPage”=癳mployee”加载比;         & lt; Grid>   & lt;按钮保证金=" 10 "点击=癇utton_Click VerticalAlignment”==?3”“顶级”高度宽度=" 100 "在进度条控制& lt;/Button>   & lt; TextBlock Name=" txtJD " VerticalAlignment=岸ゼ丁盚orizontalAlignment=爸行摹??0”在当前进度:& lt;/TextBlock>   & lt; ProgressBar高度=" 20 " HorizontalAlignment=爸行摹??167 0 0”   Name=" pb_import " VerticalAlignment==" 500 "/岸ゼ丁笨矶缺?   & lt;/Grid>   & lt;/Page>      

后台代码:

        使用系统;   使用System.Collections.Generic;   使用来;   使用text;   使用System.Windows;   使用System.Windows.Controls;   使用System.Windows.Data;   使用System.Windows.Documents;   使用System.Windows.Input;   使用System.Windows.Media;   使用System.Windows.Media.Imaging;   使用System.Windows.Navigation;   使用System.Windows.Shapes;   使用System.Threading;         名称空间WpfBrowserAppDrill   {///& lt; summary>///ProgressBarPage。xaml的交互逻辑///& lt;/summary>   公共部分类ProgressBarPage:页面   {         公共ProgressBarPage ()   {   InitializeComponent ();   }         私人空间beginImport ()   {   双精度值=https://www.yisu.com/zixun/0;   双总=100 d;//得到循环次数   而(价值<总)   {   双jd=数学。圆的(((值+ 1)* (pb_import。最大/总数)),4);         pb_import.Dispatcher。调用 (pb_import.SetValue),   System.Windows.Threading.DispatcherPriority.Background,   ProgressBar.ValueProperty,   jd);//这里是加数据或费时的操作,我这里让它挂起300毫秒   thread . sleep (300);   txtJD。文本="当前的进度是:”+(值+ 1)+”(实际值)”+ jd +”(百分比)”;   值+ +;   }   }   私人空间Button_Click(对象发送方,RoutedEventArgs e)   {   beginImport ();////新线程(新ThreadStart (beginImport)) .Start ();         }         私人空间employee(对象发送方,RoutedEventArgs e)   {   pb_import。最大=100;   pb_import。值=https://www.yisu.com/zixun/0;         }         }   }      

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

WPF ProgressBar实现实时进度效果