WPF实现进度条实时更新效果
程序员文章站
2022-07-06 12:49:19
本文实例为大家分享了wpf实现一个实时更新的进度条,供大家参考,具体内容如下
效果图
xaml代码
本文实例为大家分享了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) }); } } } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。