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"/>