最近做一个项目,看到以前同事写的进度条效果不错,所以,拿来简化了下,不炫,但是项目中还是够用的。

还是,先来看下调用以后的效果

1、因为ProgressbBar的Foreground显示不得不一样,所以,要有一个参数去给控件进行设置,因此定义了一个参数值ForegroundColor

public int ForegroundColor
{get{return _foregroundColor;
    }set{
        _foregroundColor = value;
        LinearGradientBrush lgb = dictionary["ForegroundColor" + value] as LinearGradientBrush;if (lgb != null)
            proBar.Foreground = txt.Foreground = percent.Foreground = lgb;
    }
}

代码里有这么一句话“LinearGradientBrush lgb = dictionary["ForegroundColor" + value] as LinearGradientBrush;”是为了方便通过这是这个参数去样式文件里取样式的。

<LinearGradientBrush x:Key="ForegroundColor1" EndPoint="1,0.5" StartPoint="0,0.5"><GradientStop Color="#FFBBF586" Offset="0.5"/><GradientStop Color="#FFD4F9C3" Offset="1"/></LinearGradientBrush><LinearGradientBrush x:Key="ForegroundColor2" EndPoint="1,0.5" StartPoint="0,0.5"><GradientStop Color="#FF5BE26E" Offset="0.5"/><GradientStop Color="#FF8DEC9C" Offset="1"/></LinearGradientBrush><LinearGradientBrush x:Key="ForegroundColor3" EndPoint="1,0.5" StartPoint="0,0.5"><GradientStop Color="#FFB656F2" Offset="0.5"/><GradientStop Color="#FFAE8DFE" Offset="1"/></LinearGradientBrush><LinearGradientBrush x:Key="ForegroundColor4" EndPoint="1,0.5" StartPoint="0,0.5"><GradientStop Color="#FF3AE9E9" Offset="0.5"/><GradientStop Color="#FF8DFDFE" Offset="1"/></LinearGradientBrush>

2、既然是ProgressBar就要有一个进度值,这个值,我们用TextBlock来进行显示,一定要实现通知接口,这样,才能保证实时的通知到页面上。

public string ValueText
{get{return _valueText;
    }set{
        _valueText = value;if (this.PropertyChanged != null)
        {this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("ValueText"));
        }
    }
}

3、启用一个后台线程,来不断的更新进度效果

private void Bgw_DoWork(object sender, DoWorkEventArgs e)
{for (int i = 0; i < BarValue; i++)
    {
        System.Threading.Thread.Sleep(50);
        proBar.Dispatcher.Invoke(new Action(                                     delegate{if (proBar.Value <= BarValue)
            {
                proBar.Value++;
            }
        }));
        ValueText = i + "";
    }
    ValueText = BarValue + "";
}

源码

以上就是WPF实现简单的进度条怎么做?的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

  • 相关标签:效果 进度 简易
  • 程序员必备接口测试调试工具:点击使用

    Apipost = Postman + Swagger + Mock + Jmeter

    Api设计、调试、文档、自动化测试工具

    网页生成APP,用做网站的技术去做APP:立即创建

    手机网站开发APP、自助封装APP、200+原生模块、2000+映射JS接口按需打包

    • 上一篇: Oracle Clob字段过长保存出错改如何解决?
    • 下一篇:IIS中出现了时间格式转换错误该如何解决?

    相关文章

    相关视频


    • c语言中goto语句的含义是什么
    • C/C++深度分析
    • C#中GDI+编程10个基本技巧二
    • 应用绝对路径与相对路径
    • WPF实现简单的进度条怎么做?
    • Javascript 基础教程之滑动门效果
    • CSS3 文本效果
    • php文件上传进度处理
    • SVG 模糊效果
    • CSS3 文本效果

    视频教程分类

    • php视频教程
    • html视频教程
    • css视频教程
    • JS视频教程
    • jQuery视频教程
    • mysql视频教程
    • Linux视频教程
    • Python视频教程
    • Laravel视频教程
    • Vue视频教程

    专题

    WPF实现简单的进度条怎么做?