当前位置: 移动技术网 > IT编程>开发语言>.net > WPF实现进度条实时更新效果

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

2019年01月07日  | 移动技术网IT编程  | 我要评论

本文实例为大家分享了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) });
      }
    }
  }
}

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网