zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    js点击弹出div层
    图片按比例缩小
    js标题文字向上滚动
    JS刷新当前页面
    图片缩放显示,不变形
    产品叠加搜索
    Oracle中DML基础知识
    Oracle中DDL的基础知识
    Sql多对多关系中外键的应用
    oracle 中sql语句的几个基本函数..
  • 原文地址:https://www.cnblogs.com/ExMan/p/5845678.html
Copyright © 2011-2022 走看看