在与 OneDrive 同步照片集时,如何使 CommandBar 图标像在照片应用程序中一样动画?我应该使用 GIF 图片还是有更好的方法?
最佳答案
使用 xaml 中定义的 Storyboard
很容易:
<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>
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>
在cs文件中运行和停止:
IconRotation.Begin();
IconRotation.Stop();
要更改旋转速度,请更改 Storyboard上的Duration
属性,您应该能够获得与照片应用中完全相同的动画。
关于c# - UWP(XAML 和 C#): Animated CommandBar icon,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35552630/