WPF 实现 移动带/旋转带 效果

先来看看效果:

接下来说明下实现步骤:

1.定义个背景

复制代码
 <Grid  Background="#ffffff">
     <Border Background="#7f8b99" />

</Grid>

2.定义平行四边形

定义一个 宽40 高21的 四边形。然后定义四个点的起始位置 Points

Points的定义要跟你设计的宽高相关

复制代码
   <Polygon
       Width="40"
       Height="21"
       Margin="30,0,0,0"
       Fill="#fbffff"
       Points="40,0 15,0 0,21 25,21" />

3.把多个平行四边形添加到容器中 StackPanel

我这边加了10个,容器是放在Grid里边

复制代码
  <StackPanel
      x:Name="sp_slide"
      Grid.Row="2"
      Margin="-800,0,0,0"
      HorizontalAlignment="Center"
      VerticalAlignment="Center"
      Orientation="Horizontal">
      <Polygon
          Width="40"
          Height="21"
          Margin="0,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
      <Polygon
          Width="40"
          Height="21"
          Margin="30,0,0,0"
          Fill="#fbffff"
          Points="40,0 15,0 0,21 25,21" />
  </StackPanel>

4.再来添加触发器,Grid下边

触发器修改的是容器的Margin

复制代码
<Grid.Triggers>
    <EventTrigger RoutedEvent="Grid.Loaded">
        <BeginStoryboard>
            <Storyboard RepeatBehavior="Forever">
                <ThicknessAnimation
                    AutoReverse="False"
                    BeginTime="0:0:0.00000"
                    Storyboard.TargetName="sp_slide"
                    Storyboard.TargetProperty="Margin"
                    To="-10,0,0,0"
                    Duration="0:0:8" />
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
</Grid.Triggers>

以上就是实现旋转带的方式了

相关推荐
爱写代码的小朋友33 分钟前
华三交换机配置常用命令
运维·服务器·网络
@PHARAOH41 分钟前
WHAT - Electron 系列(一)
前端·javascript·electron
loriloy41 分钟前
Electron崩溃问题排查指南
javascript·electron
wangjun51591 小时前
jenkins 参数化发布到服务器 publish over ssh、label、Parameterized publishing
服务器·ssh·jenkins
coderzpw1 小时前
当模板方法模式遇上工厂模式:一道优雅的烹饪架构设计
java·模板方法模式
直裾1 小时前
Mapreduce初使用
java·mapreduce
愚润求学1 小时前
【Linux】Linux权限
linux·服务器·语法
低头不见1 小时前
一个服务器算分布式吗,分布式需要几个服务器
运维·服务器·分布式
悠夏安末1 小时前
intellij Idea 和 dataGrip下载和安装教程
java·ide·intellij-idea
麻芝汤圆1 小时前
使用 MapReduce 进行高效数据清洗:从理论到实践
大数据·linux·服务器·网络·数据库·windows·mapreduce