WPF ProgressBar實(shí)現(xiàn)實(shí)時(shí)進(jìn)度效果
本文實(shí)例為大家分享了WPF ProgressBar實(shí)現(xiàn)實(shí)時(shí)進(jìn)度的具體代碼,供大家參考,具體內(nèi)容如下
簡(jiǎn)單測(cè)試,頁(yè)面如圖:
利用上班的一點(diǎn)點(diǎn)空閑時(shí)間,做了個(gè)wpf progressbar的例子,覺得有潛力可挖,故放上來(lái)供大家參考,有寫的更好的請(qǐng)留言哦,方便交流學(xué)習(xí),謝謝
這個(gè)xaml:
<Page x:Class="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" mc:Ignorable="d" Title="ProgressBarPage" Loaded="Page_Loaded"> <Grid> <Button Margin="10" Click="Button_Click" VerticalAlignment="Top" Height="23" Width="100">進(jìn)度條控制</Button> <TextBlock Name="txtJD" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="50">當(dāng)前進(jìn)度:</TextBlock> <ProgressBar Height="20" HorizontalAlignment="Center" Margin="8,167,0,0" Name="pb_import" VerticalAlignment="Top" Width="500" /> </Grid> </Page>
后臺(tái)代碼:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Threading; namespace WpfBrowserAppDrill { /// <summary> /// ProgressBarPage.xaml 的交互邏輯 /// </summary> public partial class ProgressBarPage : Page { public ProgressBarPage() { InitializeComponent(); } private void beginImport() { double value = 0; double total = 100d;//得到循環(huán)次數(shù) while (value < total) { double jd = Math.Round(((value + 1) * (pb_import.Maximum / total)), 4); pb_import.Dispatcher.Invoke(new Action<System.Windows.DependencyProperty, object>(pb_import.SetValue), System.Windows.Threading.DispatcherPriority.Background, ProgressBar.ValueProperty, jd); //這里是加數(shù)據(jù)或費(fèi)時(shí)的操作,我這里讓它掛起300毫秒 Thread.Sleep(300); txtJD.Text = "當(dāng)前的進(jìn)度是:" + (value + 1) + "(實(shí)際值)" + jd + "(百分比)"; value++; } } private void Button_Click(object sender, RoutedEventArgs e) { beginImport(); ////new Thread(new ThreadStart(beginImport)).Start(); } private void Page_Loaded(object sender, RoutedEventArgs e) { pb_import.Maximum = 100; pb_import.Value = 0; } } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C# 導(dǎo)出Excel的6種簡(jiǎn)單方法實(shí)現(xiàn)
C# 導(dǎo)出 Excel 的6種簡(jiǎn)單方法:數(shù)據(jù)表導(dǎo)出到 Excel,對(duì)象集合導(dǎo)出到 Excel,數(shù)據(jù)庫(kù)導(dǎo)出到 Excel,微軟網(wǎng)格控件導(dǎo)出到 Excel,數(shù)組導(dǎo)出到 Excel,CSV 導(dǎo)出到 Excel,你都會(huì)了嗎?需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09C#實(shí)現(xiàn)文件壓縮與解壓的方法示例【ZIP格式】
這篇文章主要介紹了C#實(shí)現(xiàn)文件壓縮與解壓的方法,結(jié)合具體實(shí)例形式分析了C#針對(duì)文件進(jìn)行zip格式壓縮與解壓縮的相關(guān)操作技巧,需要的朋友可以參考下2017-06-06Unity?制作一個(gè)分?jǐn)?shù)統(tǒng)計(jì)系統(tǒng)
項(xiàng)目中經(jīng)常遇到分?jǐn)?shù)統(tǒng)計(jì)的需求,例如操作正確則計(jì)分,相反則不計(jì)分失去該項(xiàng)分?jǐn)?shù),為了應(yīng)對(duì)需求需要一個(gè)分?jǐn)?shù)統(tǒng)計(jì)系統(tǒng)。本文主要介紹了通過Unity實(shí)現(xiàn)這樣的一個(gè)計(jì)分系統(tǒng),快來(lái)跟隨小編一起學(xué)習(xí)吧2021-12-12C#調(diào)用百度API實(shí)現(xiàn)活體檢測(cè)的方法
這篇文章主要給大家介紹了關(guān)于C#調(diào)用百度API實(shí)現(xiàn)活體檢測(cè)的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用C#具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09C#實(shí)現(xiàn)ComboBox變色的示例代碼
這篇文章主要為大家詳細(xì)介紹了C#如何實(shí)現(xiàn)ComboBox變色的效果,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下2023-01-01解決C# 截取當(dāng)前程序窗口指定位置截圖的實(shí)現(xiàn)方法
本篇文章是對(duì)C#中截取當(dāng)前程序窗口指定位置截圖的實(shí)現(xiàn)方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05