模仿Win10-加载中Loading:
loading
用Ellipse画一个圆点
<Ellipse Fill="Blue" Width="10" Height="10" VerticalAlignment="Bottom"/>
利用ContentControl的RenderTransform实现旋转
<ContentControl RenderTransformOrigin="0.5,0.5" x:Name="item1">
<ContentControl.RenderTransform>
<RotateTransform Angle="0"/>
</ContentControl.RenderTransform>
<Ellipse Fill="Blue" Width="10" Height="10" VerticalAlignment="Bottom"/>
</ContentControl>
RenderTransformOrigin=“0.5,0.5” 是为了设置旋转中心。
总共画五个点,如下:
<Grid Width="100" Height="100" Margin="0 50 0 0">
<ContentControl RenderTransformOrigin="0.5,0.5" x:Name="item1">
<ContentControl.RenderTransform>
<RotateTransform Angle="0"/>
</ContentControl.RenderTransform>
<Ellipse Fill="Blue" Width="10" Height="10" VerticalAlignment="Bottom"/>
</ContentControl>
<ContentControl RenderTransformOrigin="0.5,0.5" x:Name="item2">
<ContentControl.RenderTransform>
<RotateTransform Angle="0"/>
</ContentControl.RenderTransform>
<Ellipse Fill="Blue" Width="10" Height="10" VerticalAlignment="Bottom"/>
</ContentControl>
<ContentControl RenderTransformOrigin="0.5,0.5" x:Name="item3">
<ContentControl.RenderTransform>
<RotateTransform Angle="0"/>
</ContentControl.RenderTransform>
<Ellipse Fill="Blue" Width="10" Height="10" VerticalAlignment="Bottom"/>
</ContentControl>
<ContentControl RenderTransformOrigin="0.5,0.5" x:Name="item4">
<ContentControl.RenderTransform>
<RotateTransform Angle="0"/>
</ContentControl.RenderTransform>
<Ellipse Fill="Blue" Width="10" Height="10" VerticalAlignment="Bottom"/>
</ContentControl>
</Grid>
旋转代码:
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames RepeatBehavior="Forever"
Storyboard.TargetName="item1" Storyboard.TargetProperty="RenderTransform.Angle">
<SplineDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
<SplineDoubleKeyFrame Value="360" KeyTime="0:0:2" KeySpline="0.07,0.39,0.92,0.59"/>
<SplineDoubleKeyFrame Value="720" KeyTime="0:0:4" KeySpline="0.07,0.39,0.92,0.59"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" BeginTime="0:0:0.2"
Storyboard.TargetName="item2" Storyboard.TargetProperty="RenderTransform.Angle">
<SplineDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
<SplineDoubleKeyFrame Value="360" KeyTime="0:0:2" KeySpline="0.07,0.39,0.92,0.59"/>
<SplineDoubleKeyFrame Value="720" KeyTime="0:0:4" KeySpline="0.07,0.39,0.92,0.59"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" BeginTime="0:0:0.4"
Storyboard.TargetName="item3" Storyboard.TargetProperty="RenderTransform.Angle">
<SplineDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
<SplineDoubleKeyFrame Value="360" KeyTime="0:0:2" KeySpline="0.07,0.39,0.92,0.59"/>
<SplineDoubleKeyFrame Value="720" KeyTime="0:0:4" KeySpline="0.07,0.39,0.92,0.59"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" BeginTime="0:0:0.6"
Storyboard.TargetName="item4" Storyboard.TargetProperty="RenderTransform.Angle">
<SplineDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
<SplineDoubleKeyFrame Value="360" KeyTime="0:0:2" KeySpline="0.07,0.39,0.92,0.59"/>
<SplineDoubleKeyFrame Value="720" KeyTime="0:0:4" KeySpline="0.07,0.39,0.92,0.59"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
全部代码:
<Grid>
<StackPanel Margin="50">
<Button Content="开始" Width="120" Height="30">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames RepeatBehavior="Forever"
Storyboard.TargetName="item1" Storyboard.TargetProperty="RenderTransform.Angle">
<SplineDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
<SplineDoubleKeyFrame Value="360" KeyTime="0:0:2" KeySpline="0.07,0.39,0.92,0.59"/>
<SplineDoubleKeyFrame Value="720" KeyTime="0:0:4" KeySpline="0.07,0.39,0.92,0.59"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" BeginTime="0:0:0.2"
Storyboard.TargetName="item2" Storyboard.TargetProperty="RenderTransform.Angle">
<SplineDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
<SplineDoubleKeyFrame Value="360" KeyTime="0:0:2" KeySpline="0.07,0.39,0.92,0.59"/>
<SplineDoubleKeyFrame Value="720" KeyTime="0:0:4" KeySpline="0.07,0.39,0.92,0.59"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" BeginTime="0:0:0.4"
Storyboard.TargetName="item3" Storyboard.TargetProperty="RenderTransform.Angle">
<SplineDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
<SplineDoubleKeyFrame Value="360" KeyTime="0:0:2" KeySpline="0.07,0.39,0.92,0.59"/>
<SplineDoubleKeyFrame Value="720" KeyTime="0:0:4" KeySpline="0.07,0.39,0.92,0.59"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" BeginTime="0:0:0.6"
Storyboard.TargetName="item4" Storyboard.TargetProperty="RenderTransform.Angle">
<SplineDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
<SplineDoubleKeyFrame Value="360" KeyTime="0:0:2" KeySpline="0.07,0.39,0.92,0.59"/>
<SplineDoubleKeyFrame Value="720" KeyTime="0:0:4" KeySpline="0.07,0.39,0.92,0.59"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
<Grid Width="100" Height="100" Margin="0 50 0 0">
<ContentControl RenderTransformOrigin="0.5,0.5" x:Name="item1">
<ContentControl.RenderTransform>
<RotateTransform Angle="0"/>
</ContentControl.RenderTransform>
<Ellipse Fill="Blue" Width="10" Height="10" VerticalAlignment="Bottom"/>
</ContentControl>
<ContentControl RenderTransformOrigin="0.5,0.5" x:Name="item2">
<ContentControl.RenderTransform>
<RotateTransform Angle="0"/>
</ContentControl.RenderTransform>
<Ellipse Fill="Blue" Width="10" Height="10" VerticalAlignment="Bottom"/>
</ContentControl>
<ContentControl RenderTransformOrigin="0.5,0.5" x:Name="item3">
<ContentControl.RenderTransform>
<RotateTransform Angle="0"/>
</ContentControl.RenderTransform>
<Ellipse Fill="Blue" Width="10" Height="10" VerticalAlignment="Bottom"/>
</ContentControl>
<ContentControl RenderTransformOrigin="0.5,0.5" x:Name="item4">
<ContentControl.RenderTransform>
<RotateTransform Angle="0"/>
</ContentControl.RenderTransform>
<Ellipse Fill="Blue" Width="10" Height="10" VerticalAlignment="Bottom"/>
</ContentControl>
</Grid>
</StackPanel>
</Grid>
不想自己写代码的,可以在Nuget中下载XiaFControl来使用Loading控件。
XiaFControl使用教程链接:
Github:https://github.com/LiuliuMao/XiaFControl
Gitee:https://gitee.com/lm961031/xia-fcontrol
更多WPF知识分享Q群:371769310