利用WPF怎么实现一个进度条功能-创新互联
这期内容当中小编将会给大家带来有关利用WPF怎么实现一个进度条功能,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
创新互联专注于明水企业网站建设,成都响应式网站建设,成都商城网站开发。明水网站建设公司,为明水等地区提供建站服务。全流程按需求定制设计,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务实现说明
1、下载MUI相关代码或者dll文件;
2、工程中引入该dll,并引入其资源文件;
3、在需要显示进度条的页面,加入控件(其实还是WPF控件,只是MUI扩展了其样式而已);
4、后台实现,由于要根据情况更新进度文字及进度条的值。所以,这里用到了异步BackgroundWorker(具体可以网上查查相关资料);
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; namespace Monitor.Class { ////// 异步操作 /// public class CWorker { ////// 对象 /// private BackgroundWorker backgroundWorker; ////// 后台执行的操作 /// public Action BackgroundWork { get; set; } ////// 后台任务执行完毕后事件 /// public event EventHandlerBackgroundWorkerCompleted; private BackgroundWorkerEventArgs _eventArgs;//异常参数 /// /// 构造 /// public CWorker() { _eventArgs = new BackgroundWorkerEventArgs(); backgroundWorker = new BackgroundWorker(); backgroundWorker.WorkerReportsProgress = true; backgroundWorker.WorkerSupportsCancellation = true; backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork); backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted); } ////// 开始工作 /// public void BegionWork() { if (backgroundWorker.IsBusy) return; backgroundWorker.RunWorkerAsync(); } ////// 工作 /// /// /// private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { if (BackgroundWork != null) { try { BackgroundWork(); } catch (Exception ex) { _eventArgs.BackGroundException = ex; } } } ////// 完成 /// /// /// private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (this.BackgroundWorkerCompleted != null) { this.BackgroundWorkerCompleted(null, _eventArgs); } } } ////// 事件 /// public class BackgroundWorkerEventArgs : EventArgs { ////// 后台程序运行时抛出的异常 /// public Exception BackGroundException { get; set; } } }
namespace Monitor { ////// Splash.xaml 的交互逻辑 /// public partial class Splash : Window { MainWindow m_MainWindow = null;//主窗口 CWorker m_Work = null;//任务 public Splash() { InitializeComponent(); m_MainWindow = new MainWindow();//创建主窗口对象 m_Work = new CWorker(); m_Work.BackgroundWork = this.ProcessDo; m_Work.BackgroundWorkerCompleted += new EventHandler(m_Work_BackgroundWorkerCompleted); } /// /// 进度提示 /// public void ProcessDo() { m_MainWindow.InitData(this); } ////// 移动 /// /// /// private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { this.DragMove(); } ////// 窗口加载 /// /// /// private void Window_Loaded(object sender, RoutedEventArgs e) { m_Work.BegionWork(); } ////// 执行完成 /// /// /// void m_Work_BackgroundWorkerCompleted(object sender, BackgroundWorkerEventArgs e) { m_MainWindow.Show(); this.Close(); } ////// 赋值 /// /// private delegate void SetProcessLabelDelegate(string text, double processValue); public void SetProcessValue(string text, double processValue) { if (!Dispatcher.CheckAccess()) { Dispatcher.Invoke(DispatcherPriority.Send, new SetProcessLabelDelegate(SetProcessValue), text, processValue); return; } this.lblProcess.Content = text; this.ProgressControlRealValue.Value = processValue; } } }
上述就是小编为大家分享的利用WPF怎么实现一个进度条功能了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。
本文标题:利用WPF怎么实现一个进度条功能-创新互联
URL网址:http://scyanting.com/article/jehod.html