WPF ProgressBar實(shí)現(xiàn)實(shí)時(shí)進(jìn)度效果
本文實(shí)例為大家分享了WPF ProgressBar實(shí)現(xiàn)實(shí)時(shí)進(jìn)度的具體代碼,供大家參考,具體內(nèi)容如下
簡(jiǎn)單測(cè)試,頁面如圖:
利用上班的一點(diǎn)點(diǎn)空閑時(shí)間,做了個(gè)wpf progressbar的例子,覺得有潛力可挖,故放上來供大家參考,有寫的更好的請(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í)有所幫助,也希望大家多多支持我們。
上一篇:string與stringbuilder兩者的區(qū)別
欄 目:C#教程
下一篇:c#獲取兩個(gè)特定字符之間的內(nèi)容并輸出的方法
本文標(biāo)題:WPF ProgressBar實(shí)現(xiàn)實(shí)時(shí)進(jìn)度效果
本文地址:http://www.jygsgssxh.com/a1/C_jiaocheng/4958.html
您可能感興趣的文章
- 01-10C#實(shí)現(xiàn)txt定位指定行完整實(shí)例
- 01-10WinForm實(shí)現(xiàn)仿視頻播放器左下角滾動(dòng)新聞效果的方法
- 01-10C#實(shí)現(xiàn)清空回收站的方法
- 01-10C#實(shí)現(xiàn)讀取注冊(cè)表監(jiān)控當(dāng)前操作系統(tǒng)已安裝軟件變化的方法
- 01-10C#實(shí)現(xiàn)多線程下載文件的方法
- 01-10C#實(shí)現(xiàn)Winform中打開網(wǎng)頁頁面的方法
- 01-10C#實(shí)現(xiàn)遠(yuǎn)程關(guān)閉計(jì)算機(jī)或重啟計(jì)算機(jī)的方法
- 01-10C#自定義簽名章實(shí)現(xiàn)方法
- 01-10C#文件斷點(diǎn)續(xù)傳實(shí)現(xiàn)方法
- 01-10winform實(shí)現(xiàn)創(chuàng)建最前端窗體的方法


閱讀排行
- 1C語言 while語句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹的示例代碼(圣誕
- 3利用C語言實(shí)現(xiàn)“百馬百擔(dān)”問題方法
- 4C語言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 01-10C#通過反射獲取當(dāng)前工程中所有窗體并
- 01-10關(guān)于ASP網(wǎng)頁無法打開的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#實(shí)現(xiàn)txt定位指定行完整實(shí)例
- 01-10WinForm實(shí)現(xiàn)仿視頻播放器左下角滾動(dòng)新
- 01-10C#停止線程的方法
- 01-10C#實(shí)現(xiàn)清空回收站的方法
- 01-10C#通過重寫Panel改變邊框顏色與寬度的
- 01-10C#實(shí)現(xiàn)讀取注冊(cè)表監(jiān)控當(dāng)前操作系統(tǒng)已
隨機(jī)閱讀
- 04-02jquery與jsp,用jquery
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 01-10使用C語言求解撲克牌的順子及n個(gè)骰子
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 01-10C#中split用法實(shí)例總結(jié)
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 01-11ajax實(shí)現(xiàn)頁面的局部加載
- 01-10delphi制作wav文件的方法


