码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2016-09-06 15:10:12      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

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

 技术分享

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>

 

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

标签:

原文地址:http://www.cnblogs.com/ExMan/p/5845678.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!