WPF 斜向进度条Progressbar

WPF 斜向进度条Progressbar

在这里插入图片描述

用户控件类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace demo小记wpf
{
    /// <summary>
    /// ObliquePB.xaml 的交互逻辑
    /// </summary>
    public partial class ObliquePB : UserControl
    {
        public ObliquePB()
        {
            InitializeComponent();
        }

        public int PBValue
        {
            get { return (int)GetValue(PBValueProperty); }
            set { SetValue(PBValueProperty, value); }
        }

        // Using a DependencyProperty as the backing store for PBValue.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty PBValueProperty =
            DependencyProperty.Register("PBValue", typeof(int), typeof(ObliquePB), new PropertyMetadata(0));

        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);
            StringBuilder stringBuilder = new StringBuilder();
            for (int p = 0; p < 20; p++)
            {
                stringBuilder.Clear();
                stringBuilder.Append("M" + (42 + 15 * p) + ",3 " + (10 + 15 * p) + ",27 " + (19 + 15 * p) + ",27 " + (51 + 15 * p) + ",3z");
                PathGeometry path = new PathGeometry
                {
                    Figures = PathFigureCollection.Parse(stringBuilder.ToString())
                };
                GeoGroup1.Children.Add(path);
            }
        }

        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            base.OnPropertyChanged(e);
            if (e.Property.Name == "PBValue")
            {
                GeoGroup2.Children.Clear();
                StringBuilder stringBuilder = new StringBuilder();
                for (int p = 0; p < (Convert.ToInt32(e.NewValue) <= 20 ? Convert.ToInt32(e.NewValue) : Convert.ToInt32(e.NewValue) % 20); p++)
                {
                    stringBuilder.Clear();
                    stringBuilder.Append("M" + (42 + 15 * p) + ",3 " + (10 + 15 * p) + ",27 " + (19 + 15 * p) + ",27 " + (51 + 15 * p) + ",3z");
                    PathGeometry path = new PathGeometry
                    {
                        Figures = PathFigureCollection.Parse(stringBuilder.ToString())
                    };
                    GeoGroup2.Children.Add(path);
                }
            }
        }
    }
}

xaml代码

<UserControl x:Class="demo小记wpf.ObliquePB"
             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" 
             xmlns:local="clr-namespace:demo小记wpf"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
        <Path Margin="2" Grid.Column="1" Fill="Yellow" Stroke="Red" StrokeThickness="1" Data="M40,0 0,30 306,30 346,0Z"/>

        <Path Margin="2" Grid.Column="1" Fill="Blue">
            <Path.Data>
                <GeometryGroup x:Name="GeoGroup1"/>
                <!--<PathGeometry Figures="M42,3 10,27 19,27 51,3Z"/>
                    <PathGeometry Figures="M57,3 25,27 34,27 66,3Z"/>
                    <PathGeometry Figures="M72,3 40,27 49,27 81,3Z"/>
                    <PathGeometry Figures="M87,3 55,27 64,27 96,3Z"/>
                    <PathGeometry Figures="M102,3 70,27 79,27 111,3Z"/>
                    <PathGeometry Figures="M117,3 85,27 94,27 126,3Z"/>-->
            </Path.Data>
        </Path>
        <Path Margin="2" Grid.Column="1" Fill="Green">
            <Path.Data>
                <GeometryGroup x:Name="GeoGroup2">
                </GeometryGroup>
            </Path.Data>
        </Path>
    </Grid>
</UserControl>

引用代码

<local:ObliquePB Grid.Column="1" PBValue="5"/>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

溧阳苏东坡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值