本文实例为大家分享了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) }); } } } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
故事向|在3A游戏公司工作多年的3D建模师自述,制作3A大作经验心得(上)
「建模学习」zbrush中如何制作拉链?拉链笔刷来帮忙,轻松搞定
LeetCode hot-100 简单and中等难度,21-30.
Second season eighth episode,Ross made a list about Rachel,compared to Julie??!!
2020.08.07 J - MaratonIME goes to Mito
网友评论