WPF 进度条ProgressBar

今天研究了一下wpf的进度条ProgressBar

1.传统ProgressBar

WPF进度条ProgressBar 这个控件,如果直接写到循环里,会死掉,界面会卡死,不会有进度。需要把进度条放到单独的线程中。

传统的需要建立 Thread 或者使用 Timer,分别写在不同的方法中。但现在,使用 Dispatcher.Invoke 调用可以实现这个目的。

for (int i = 0; i <= 10000; i++)
            {
                double value = i * 100.0 / 10000;
                lbShow.Content = "总大小:" + 10000 + ",已导入:" + i;
                pbBar.Dispatcher.Invoke(new Action<System.Windows.DependencyProperty, object>(pbBar.SetValue), System.Windows.Threading.DispatcherPriority.Background, ProgressBar.ValueProperty, value);
            }

pbBar是ProgressBar的名称。下图是传统进度条显示的效果。

传统的进度条看着比价简单,没有高大上的感觉。所以一般很少受到广大人民的喜好。

2.圆形进度条(这是借鉴了网上一位网友的,如侵犯到版权,请给我留言)

圆形进度条,如下图,同样是用ProgressBar控件,但感觉就会不一样

要显示这个效果,首先要编写一个类,这里编写的类是ValueToProcessConverter.cs类,源码是

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace WpfSqlHelp
{
    class ValueToProcessConverter : IValueConverter
    {
        private const double Thickness = 8;
        private const double Padding = 1;
        private const double WarnValue = 60;
        private const int SuccessRateFontSize = 34;
        private static readonly SolidColorBrush NormalBrush;
        private static readonly SolidColorBrush WarnBrush;
        private static readonly Typeface SuccessRateTypeface;

        private string percentString;
        private Point centerPoint;
        private double radius;

        static ValueToProcessConverter()
        {
            NormalBrush = new SolidColorBrush(Colors.Green);
            WarnBrush = new SolidColorBrush(Colors.Red);
            SuccessRateTypeface = new Typeface(new FontFamily("MSYH"), n
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值