相思资源网 Design By www.200059.com

本文实例为大家分享了WPF实现一个实时更新的进度条,供大家参考,具体内容如下

效果图

WPF实现进度条实时更新效果

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) });
      }
    }
  }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。 

标签:
WPF进度条实时更新,WPF进度条更新,WPF进度条

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“WPF实现进度条实时更新效果”

暂无WPF实现进度条实时更新效果的评论...