WPF进度条系列②旋转小圆圈

 写在之前:

关于WPF的样式,我也是学习了很多朋友的文章才有了下面的东西,因为时间有些久远 & 备份的链接也都不在了。

所以,究竟是看过哪些文章,也是记不清楚了……

请见谅。

--------------------------------我是害羞的分割线-----------------------------------

旋转小圆圈进度条见效果:

xaml:

<UserControl x:Class="AppHost.ProbarRotate"
             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="300" d:DesignWidth="300"> 
    <UserControl.Resources>
        <ResourceDictionary>
            <Style x:Key="EllipseStyle" TargetType="Ellipse">
                <Setter Property="Width" Value="16"/>
                <Setter Property="Height" Value="16"/>
                <Setter Property="Stretch" Value="Fill"/>
                <Setter Property="Fill" Value="#FF2CB6E7"/>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="Transparent" 
              HorizontalAlignment="Center" VerticalAlignment="Center">
        <Grid.RenderTransform> 
            <ScaleTransform x:Name="SpinnerScale"   ScaleX="1.0" ScaleY="1.0" /> 
        </Grid.RenderTransform>
        <Canvas RenderTransformOrigin="0.5,0.5"  Width="120" Height="120" 
                HorizontalAlignment="Center" VerticalAlignment="Center" >
            <Ellipse  Style="{StaticResource EllipseStyle}" Opacity="1.0" 
                      Canvas.Left="14.64"  Canvas.Top="14.64" />
            <Ellipse Style="{StaticResource EllipseStyle}" Opacity="0.8" 
                     Canvas.Left="0" Canvas.Top="50"  />
            <Ellipse Style="{StaticResource EllipseStyle}" Opacity="0.6" 
                     Canvas.Left="14.64" Canvas.Top="85.35"  />
            <Ellipse  Style="{StaticResource EllipseStyle}" Opacity="0.4" 
                      Canvas.Left="50"  Canvas.Top="100" />
            <Ellipse Style="{StaticResource EllipseStyle}" Opacity="0.2" 
                     Canvas.Left="85.35" Canvas.Top="85.35"  />
            <Ellipse Style="{StaticResource EllipseStyle}" Opacity="0.1" 
                     Canvas.Left="100" Canvas.Top="50"  />
            <Canvas.RenderTransform> 
                <RotateTransform x:Name="SpinnerRotate"  Angle="0" /> 
            </Canvas.RenderTransform> 
            <Canvas.Triggers> 
                <EventTrigger RoutedEvent="ContentControl.Loaded"> 
                    <BeginStoryboard> 
                        <Storyboard> 
                            <DoubleAnimation 
                                    Storyboard.TargetName  ="SpinnerRotate"  
                                    Storyboard.TargetProperty ="(RotateTransform.Angle)" 
                                     From="0" To="360"  Duration="0:0:05" RepeatBehavior="Forever" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Canvas.Triggers>
        </Canvas>   
    </Grid> 
</UserControl>


使用方法与系列①类似。

 

转载于:https://www.cnblogs.com/YunGy/p/5007291.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用C# WPF实现圆形进度条的代码示例: ```csharp <Window x:Class="CircularProgressBar.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Circular Progress Bar" Height="350" Width="350"> <Grid> <Ellipse Width="100" Height="100" Stroke="Gray" StrokeThickness="10"> <Ellipse.Clip> <EllipseGeometry Center="50,50" RadiusX="45" RadiusY="45"/> </Ellipse.Clip> </Ellipse> <Path x:Name="progressIndicator" Stroke="Blue" StrokeThickness="10"> <Path.Data> <PathGeometry> <PathFigure x:Name="progressFigure" StartPoint="50,5"> <ArcSegment x:Name="progressArc" Point="50,5" Size="45,45" SweepDirection="Clockwise"/> </PathFigure> </PathGeometry> </Path.Data> </Path> </Grid> </Window> ``` 在代码中,我们使用了一个`Ellipse`元素来绘制圆形进度条的背景,使用`Path`元素来绘制进度条的前景。`Path`元素中的`PathFigure`和`ArcSegment`元素用于绘制圆弧。 接下来,我们需要在C#代码中实现进度条的动态效果。我们可以使用`Storyboard`和`DoubleAnimation`来实现进度条的动态效果。以下是C#代码示例: ```csharp public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); Loaded += MainWindow_Loaded; } private void MainWindow_Loaded(object sender, RoutedEventArgs e) { var storyboard = new Storyboard(); var animation = new DoubleAnimation(0, 360, new Duration(TimeSpan.FromSeconds(5))); Storyboard.SetTarget(animation, progressArc); Storyboard.SetTargetProperty(animation, new PropertyPath(ArcSegment.EndAngleProperty)); storyboard.Children.Add(animation); storyboard.Begin(); } } ``` 在代码中,我们创建了一个`Storyboard`对象,并使用`DoubleAnimation`来实现进度条的动态效果。`Storyboard.SetTarget`和`Storyboard.SetTargetProperty`方法用于将动画应用到`progressArc`元素的`EndAngle`属性上。最后,我们调用`storyboard.Begin()`方法来启动动画。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值