這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)利用WPF怎么實(shí)現(xiàn)一個(gè)進(jìn)度條功能,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
創(chuàng)新互聯(lián)專注于明水企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè),成都商城網(wǎng)站開(kāi)發(fā)。明水網(wǎng)站建設(shè)公司,為明水等地區(qū)提供建站服務(wù)。全流程按需求定制設(shè)計(jì),專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)實(shí)現(xiàn)說(shuō)明
1、下載MUI相關(guān)代碼或者dll文件;
2、工程中引入該dll,并引入其資源文件;
3、在需要顯示進(jìn)度條的頁(yè)面,加入控件(其實(shí)還是WPF控件,只是MUI擴(kuò)展了其樣式而已);
4、后臺(tái)實(shí)現(xiàn),由于要根據(jù)情況更新進(jìn)度文字及進(jìn)度條的值。所以,這里用到了異步BackgroundWorker(具體可以網(wǎng)上查查相關(guān)資料);
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; namespace Monitor.Class { ////// 異步操作 /// public class CWorker { ////// 對(duì)象 /// private BackgroundWorker backgroundWorker; ////// 后臺(tái)執(zhí)行的操作 /// public Action BackgroundWork { get; set; } ////// 后臺(tái)任務(wù)執(zhí)行完畢后事件 /// public event EventHandlerBackgroundWorkerCompleted; private BackgroundWorkerEventArgs _eventArgs;//異常參數(shù) /// /// 構(gòu)造 /// 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); } ////// 開(kāi)始工作 /// 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 { ////// 后臺(tái)程序運(yùn)行時(shí)拋出的異常 /// public Exception BackGroundException { get; set; } } }
namespace Monitor { ////// Splash.xaml 的交互邏輯 /// public partial class Splash : Window { MainWindow m_MainWindow = null;//主窗口 CWorker m_Work = null;//任務(wù) public Splash() { InitializeComponent(); m_MainWindow = new MainWindow();//創(chuàng)建主窗口對(duì)象 m_Work = new CWorker(); m_Work.BackgroundWork = this.ProcessDo; m_Work.BackgroundWorkerCompleted += new EventHandler(m_Work_BackgroundWorkerCompleted); } /// /// 進(jìn)度提示 /// public void ProcessDo() { m_MainWindow.InitData(this); } ////// 移動(dòng) /// /// /// private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { this.DragMove(); } ////// 窗口加載 /// /// /// private void Window_Loaded(object sender, RoutedEventArgs e) { m_Work.BegionWork(); } ////// 執(zhí)行完成 /// /// /// 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怎么實(shí)現(xiàn)一個(gè)進(jìn)度條功能了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。