环形进度条(原创)

一直都是在博客园上看别人的分享 今天就突然心血来潮想把自己以前写的一个环形进度条分享给大家

这是我的第一篇博客,希望大家多多指教;

在这里我使用了blend里面的Arc控件 和一个定时器来控制endangle 值 

项目的结构如下:

xaml代码如下:

<Window
        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:Arc"
        xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" x:Class="Arc.MainWindow"
        mc:Ignorable="d"
        x:Name="mainwindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ed:Arc ArcThickness="20" ArcThicknessUnit="Pixel" EndAngle="{Binding EndAngle,ElementName=mainwindow}" Fill="Yellow" HorizontalAlignment="Left" Margin="155.783,113.934,0,106.066" Stretch="None" Stroke="Gray" StartAngle="0" Width="100"/>
        <ed:Arc ArcThickness="20" ArcThicknessUnit="Pixel" EndAngle="360" Fill="Transparent" HorizontalAlignment="Left" Margin="155.783,113.934,0,106.066" Stretch="None" Stroke="Black" StartAngle="0" Width="100"/>
    </Grid>
</Window>

注意:在这里需要注意 如果你只是安装了vs但是么有blend 你需要在项目中添加Microsoft.Expression.Drawing.dll 这个类库

然后添加引用 再添加命名空间

xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" x:Class="Arc.MainWindow"这个命名空间哦 


后台代码如下:
using System;
using System.Windows;
using System.Windows.Threading;

namespace Arc
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += MainWindow_Loaded;
        }
        DispatcherTimer Time = new DispatcherTimer();

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            Time.Tick += new EventHandler(Time_Tick);
            Time.Interval = new TimeSpan(10000);
            Time.Start();
        }

        private void Time_Tick(object sender, EventArgs e)
        {
            if (EndAngle < 360)
            {
                EndAngle++;
            }
            else
            {
                EndAngle = 360;
            }
        }

        public double EndAngle
        {
            get { return (double)GetValue(EndAngleProperty); }
            set { SetValue(EndAngleProperty, value); }
        }
        public static readonly DependencyProperty EndAngleProperty =
            DependencyProperty.Register("EndAngle", typeof(double), typeof(MainWindow), new PropertyMetadata(0d));



    }
}

如果想显示进度值可以自己添加哦 在这里我就不写了

 

 

转载于:https://www.cnblogs.com/liu1314/p/5764277.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值