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的例子,覺(jué)得有潛力可挖,故放上來(lái)供大家參考,有寫(xiě)的更好的請(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#使用控制臺(tái)列出當(dāng)前所有可用的打印機(jī)列表
這篇文章主要介紹了C#使用控制臺(tái)列出當(dāng)前所有可用的打印機(jī)列表,涉及C#操作計(jì)算機(jī)硬件的相關(guān)使用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04
c#封裝百度web服務(wù)geocoding api 、百度坐標(biāo)轉(zhuǎn)換示例
這篇文章主要介紹了c#封裝百度Web服務(wù)geocoding api 、百度坐標(biāo)轉(zhuǎn)換,需要的朋友可以參考下2014-04-04
C#利用RabbitMQ實(shí)現(xiàn)點(diǎn)對(duì)點(diǎn)消息傳輸
RabbitMQ做為消息代理,負(fù)責(zé)接收和轉(zhuǎn)發(fā)消息,可以將RabbitMQ比喻為一個(gè)郵筒、一個(gè)郵局和一個(gè)郵遞員。本文主要以一個(gè)簡(jiǎn)單的小例子,簡(jiǎn)述RabbitMQ實(shí)現(xiàn)消息傳輸?shù)南嚓P(guān)內(nèi)容,僅供學(xué)習(xí)分享使用,如有不足之處,還請(qǐng)指正。2021-05-05
C#實(shí)現(xiàn)對(duì)象XML序列化的方法
這篇文章主要介紹了C#實(shí)現(xiàn)對(duì)象XML序列化的方法,是C#常見(jiàn)的實(shí)用技巧,需要的朋友可以參考下2014-11-11
C#中結(jié)構(gòu)(struct)的部分初始化和完全初始化實(shí)例分析
這篇文章主要介紹了C#中結(jié)構(gòu)(struct)的部分初始化和完全初始化,通過(guò)實(shí)例分析了結(jié)構(gòu)初始化中常見(jiàn)的錯(cuò)誤及技巧,有助于加深對(duì)C#結(jié)構(gòu)(struct)的認(rèn)識(shí),需要的朋友可以參考下2014-09-09
C#控制Excel Sheet使其自適應(yīng)頁(yè)寬與列寬的方法
這篇文章主要介紹了C#控制Excel Sheet使其自適應(yīng)頁(yè)寬與列寬的方法,涉及C#操作Excel的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06

