添加引用:Microsoft.Expression.Drawing.dll
下载地址:https://download.csdn.net/download/qq_43307934/10923136
适用于.NET 4.0
XAML增加命名空间:
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" mc:Ignorable="d"
<Grid Width=" 150"
Grid.Row=" 1"
Height=" 150">
<Ellipse Stroke="Gray"
StrokeThickness="3"
Opacity="0.6" />
<ed:Arc ArcThickness="15"
EndAngle="180"
Margin="0"
Stretch="None"
Stroke="Transparent"
StrokeThickness="0"
StartAngle="0"
Fill="#FF0071BC"
x:Name="EllipseFill" />
<TextBlock Foreground="Green"
FontSize="30"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="0,-40,0,0"
Text="0%"
x:Name="TValue"
FontFamily="Segoe UI" />
<TextBlock Foreground="Red"
FontSize="17"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="0,0,0,-45"
x:Name="TText"
Text="加载中……"
FontFamily="Segoe UI Light" />
</Grid>
后台部分代码:
DispatcherTimer timer = new DispatcherTimer();
private int angle = 0;
public MainWindow()
{
InitializeComponent();
timer.Tick += new EventHandler(timer_Tick);
timer.Interval = TimeSpan.FromMilliseconds(1);
timer.Start();
}
public void timer_Tick(object sender, EventArgs e)
{
if (angle<360)
{
angle++;
EllipseFill.EndAngle = angle;
}
else
{
angle = 0;
EllipseFill.EndAngle = angle;
}
}