环形进度条(原创)

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

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

在这里我使用了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