• 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>
  • 相关阅读:
    一、ThinkPHP的介绍
    一、ThinkPHP的介绍
    perl 爬虫两个技巧
    perl 爬虫两个技巧
    perl 爬取上市公司业绩预告
    perl lwp get uft-8和gbk
    perl lwp get uft-8和gbk
    perl 爬取同花顺数据
    perl 爬取同花顺数据
    php 接口示例
  • 原文地址:https://www.cnblogs.com/ExMan/p/5845678.html
Copyright © 2020-2023  润新知