UWP(XAML&C#):动画CommandBar图标

Jan*_*upa 2 c# animation xaml win-universal-app windows-10

在使用OneDrive同步照片集期间,如何使照片应用程序中的CommandBar图标动画化?我应该使用GIF图像还是有更好的方法来做到这一点?

Ala*_*bra 8

Storyboard在xaml中定义很容易:

 <Page.Resources>
    <Storyboard x:Name="IconRotation" AutoReverse="False" RepeatBehavior="Forever">
        <DoubleAnimation Duration="0:0:1" To="360" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="symbolIcon" />
   </Storyboard>
 </Page.Resources>
Run Code Online (Sandbox Code Playgroud)

SymbolIcon,AppBarButton和CommandBar:

<CommandBar>
  <AppBarButton>
    <AppBarButton.Icon>
     <SymbolIcon x:Name="symbolIcon"  Symbol="Sync" RenderTransformOrigin="0.5,0.5" >
       <SymbolIcon.RenderTransform>
          <CompositeTransform/>
       </SymbolIcon.RenderTransform>
      </SymbolIcon>
     </AppBarButton.Icon>
    </AppBarButton>
  </CommandBar>
Run Code Online (Sandbox Code Playgroud)

运行它并在cs文件中停止它:

IconRotation.Begin();
IconRotation.Stop();
Run Code Online (Sandbox Code Playgroud)

要更改旋转速度,请更改Duration故事板上的属性,您应该能够像在Photo应用程序中那样获得完全相同的动画.