WPF 自定义绕圈进度条(转)

在设计界面时,有时会遇到进度条,本次讲解如何设计自定义的绕圈进度条,直接上代码:

 

1、控件界面

复制代码
<UserControl x:Class="ProgressBarControl" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d" d:DesignHeight="200" d:DesignWidth="300"
             Background="Gray" Loaded="ProgressBarControl_OnLoaded">

    <Grid>
        <Grid.Resources>
            <Style TargetType="Ellipse">
                <Setter Property="Height" Value="{Binding EclipseSize}"></Setter>
                <Setter Property="Width" Value="{Binding EclipseSize}"></Setter>
                <Setter Property="Stretch" Value="Fill"></Setter>
                <!--设置圆的颜色-->
                <Setter Property="Fill" Value="White"></Setter>
            </Style>
        </Grid.Resources>
        <StackPanel   HorizontalAlignment="Center"  
            VerticalAlignment="Center">
            <Viewbox Width="{Binding ViewBoxSize}" Height="{Binding ViewBoxSize}"  
            HorizontalAlignment="Center"  
            VerticalAlignment="Center">
                <Grid x:Name="LayoutRoot"   
                Background="Transparent"  
                HorizontalAlignment="Center"  
                VerticalAlignment="Center">
                    <!--此处有canvas的加载和卸载事件-->
                    <Canvas x:Name="ProgressBarCanvas" RenderTransformOrigin="0.5,0.5"  
                    HorizontalAlignment="Center"  
                    VerticalAlignment="Center" Width="{Binding CanvasSize}"  
                    Height="{Binding CanvasSize}" Loaded="HandleLoaded"  
                    Unloaded="HandleUnloaded"  >
                        <!--画圆-->                        
                        <Canvas.RenderTransform>
                            <RotateTransform x:Name="SpinnerRotate" Angle="0" />
                        </Canvas.RenderTransform>
                    </Canvas>
                </Grid>
            </Viewbox>
        </StackPanel>
    </Grid>
</UserControl> 
复制代码

 

2、控件后台逻辑:

 控件后台:

  View Code

数据Model类: 

复制代码
/// <summary>
    /// 进度条Model类
    /// </summary>
    public class ProgressBarDataModel
    {
        public double EclipseSize { get; set; }
        public double CanvasSize { get; set; }
        public double ViewBoxSize
        {
            get
            {
                double length = Convert.ToDouble(CanvasSize) - Convert.ToDouble(EclipseSize);
                return length;
            }
        }
        public double EclipseLeftLength
        {
            get
            {
                double length = Convert.ToDouble(CanvasSize) / 2;
                return length;
            }
        }
        public double R
        {
            get
            {
                double length = (Convert.ToDouble(CanvasSize) - Convert.ToDouble(EclipseSize)) / 2;
                return length;
            }
        }
    }

 

复制代码

 

3、取用控件

<control:ProgressBarControl  CanvasSize="100" EllipseCount="9" EllipseSize="10" StepAngle="10" TimeSpan="200"></control:ProgressBarControl>

 

转载于:https://www.cnblogs.com/ExMan/p/5845678.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值