WPF實現(xiàn)進度條實時更新效果
本文實例為大家分享了WPF實現(xiàn)一個實時更新的進度條,供大家參考,具體內(nèi)容如下
效果圖

xaml代碼
<Window x:Class="ProgressBar.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ProgressBar"
mc:Ignorable="d"
Title="MainWindow" Height="250" Width="400">
<Grid>
<ProgressBar Name="progressBar" Minimum="1" Maximum="1000" Height="50"/>
<Button Content="Done" VerticalAlignment="Bottom" HorizontalAlignment="Center" FontSize="20" Margin="10" Click="Button_Click"/>
</Grid>
</Window>
后臺代碼
using System;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Threading;
namespace ProgressBar
{
/// <summary>
/// MainWindow.xaml 的交互邏輯
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private delegate void UpdateProgressBarDelegate(DependencyProperty dp, object value);
private void Button_Click(object sender, RoutedEventArgs e)
{
UpdateProgressBarDelegate updateProgressBaDelegate = new UpdateProgressBarDelegate(progressBar.SetValue);
for (int i = (int)progressBar.Minimum; i <= (int)progressBar.Maximum; i++)
{
Dispatcher.Invoke(updateProgressBaDelegate, DispatcherPriority.Background, new object[] { RangeBase.ValueProperty, Convert.ToDouble(i) });
}
}
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
ASP.NET SignaiR 實現(xiàn)消息的即時推送,并使用Push.js實現(xiàn)通知的示例代碼
ASP.NET SignalR 是為 ASP.NET 開發(fā)人員提供的一個庫,可以簡化開發(fā)人員將實時 Web 功能添加到應(yīng)用程序的過程。有興趣的可以了解一下。2017-01-01
.net 通過URL推送POST數(shù)據(jù)具體實現(xiàn)
這篇文章主要介紹了.net 通過URL推送POST數(shù)據(jù)具體實現(xiàn),有需要的朋友可以參考一下2013-12-12
ASP.NET?Core通過Microsoft.AspNetCore.App元包簡化程序集引用
這篇文章介紹了ASP.NET?Core通過Microsoft.AspNetCore.App元包簡化程序集引用的方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-07-07
Asp.net SignalR創(chuàng)建實時聊天應(yīng)用程序
這篇文章主要介紹了Asp.net SignalR創(chuàng)建實時聊天應(yīng)用程序,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11
ASP.NET Core使用JWT自定義角色并實現(xiàn)策略授權(quán)需要的接口
這篇文章介紹了ASP.NET Core使用JWT自定義角色并實現(xiàn)策略授權(quán)需要的接口,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-01-01
.net Core 使用IHttpClientFactory請求實現(xiàn)
這篇文章主要介紹了.net Core 使用IHttpClientFactory請求實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01

