XAML .net 文本块动画旋转
XAML .net Text Block Animated Rotation
基本运行下来。
我有一个 windows 表单,它使用元素宿主对象在子 XAML 视图之间切换。我正在使用 FontAwesome 微调器图标来旋转并指示 activity 正在发生。我已经缩小范围,我要么不能设置正确的 属性 路径,要么在尝试修改角度时需要一些额外的东西。
相关对象:
<TextBlock x:Name="status_1" HorizontalAlignment="Right" Margin="288,95,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" FontFamily="/InstallerPanes;component/App_Plugins/FontAwesomeIconsDD/assets/font-awesome/fonts/#FontAwesome" Visibility="Visible" RenderTransformOrigin="0.5,0.5">
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="0"/>
<TranslateTransform/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
按下按钮后开始转换的代码:
status_1.Visibility = System.Windows.Visibility.Visible;
status_2.Visibility = System.Windows.Visibility.Visible;
_ani = new DoubleAnimation(0,360, TimeSpan.FromSeconds(5));
_ani.AutoReverse = false;
_ani.RepeatBehavior = System.Windows.Media.Animation.RepeatBehavior.Forever;
Storyboard story = new Storyboard();
story.Children.Add(_ani);
Storyboard.SetTarget(_ani, status_1);
Storyboard.SetTargetProperty(_ani, new PropertyPath("(TextBlock.RenderTransform).(RotateTransform.Angle)"));
story.Begin(this);
如果我将 PropertyPath 更改为 PropertyPath("Width") 然后我可以看到一个动画发生导致图标从宽度扩展侧向滑动。所以我知道其余的设置有效。
不过我也知道,如果我把路径放错了,就会出错,所以原来的路径一定是有效的。我还知道,如果我将 Angle 的 XAML 值修改为其他值,渲染中会发生实际旋转,所以我知道旋转是可能的。我究竟做错了什么?
尝试使用此代码段:
<TextBlock.RenderTransform>
<TransformGroup>
<RotateTransform Angle="0" x:Name="textRotation"/>
</TransformGroup>
</TextBlock.RenderTransform>
在代码隐藏中:
_ani = new DoubleAnimation(0, 360, TimeSpan.FromSeconds(5));
_ani.AutoReverse = false;
_ani.RepeatBehavior = RepeatBehavior.Forever;
textRotation.BeginAnimation(RotateTransform.AngleProperty, _ani);
试试这个
<TextBlock x:Name="status_1" HorizontalAlignment="Right" Margin="288,95,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" FontFamily="/InstallerPanes;component/App_Plugins/FontAwesomeIconsDD/assets/font-awesome/fonts/#FontAwesome" Visibility="Visible" RenderTransformOrigin="0.5,0.5">
<TextBlock.RenderTransform>
<RotateTransform Angle="0"/>
</TextBlock.RenderTransform>
</TextBlock>
基本运行下来。
我有一个 windows 表单,它使用元素宿主对象在子 XAML 视图之间切换。我正在使用 FontAwesome 微调器图标来旋转并指示 activity 正在发生。我已经缩小范围,我要么不能设置正确的 属性 路径,要么在尝试修改角度时需要一些额外的东西。
相关对象:
<TextBlock x:Name="status_1" HorizontalAlignment="Right" Margin="288,95,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" FontFamily="/InstallerPanes;component/App_Plugins/FontAwesomeIconsDD/assets/font-awesome/fonts/#FontAwesome" Visibility="Visible" RenderTransformOrigin="0.5,0.5">
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="0"/>
<TranslateTransform/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
按下按钮后开始转换的代码:
status_1.Visibility = System.Windows.Visibility.Visible;
status_2.Visibility = System.Windows.Visibility.Visible;
_ani = new DoubleAnimation(0,360, TimeSpan.FromSeconds(5));
_ani.AutoReverse = false;
_ani.RepeatBehavior = System.Windows.Media.Animation.RepeatBehavior.Forever;
Storyboard story = new Storyboard();
story.Children.Add(_ani);
Storyboard.SetTarget(_ani, status_1);
Storyboard.SetTargetProperty(_ani, new PropertyPath("(TextBlock.RenderTransform).(RotateTransform.Angle)"));
story.Begin(this);
如果我将 PropertyPath 更改为 PropertyPath("Width") 然后我可以看到一个动画发生导致图标从宽度扩展侧向滑动。所以我知道其余的设置有效。
不过我也知道,如果我把路径放错了,就会出错,所以原来的路径一定是有效的。我还知道,如果我将 Angle 的 XAML 值修改为其他值,渲染中会发生实际旋转,所以我知道旋转是可能的。我究竟做错了什么?
尝试使用此代码段:
<TextBlock.RenderTransform>
<TransformGroup>
<RotateTransform Angle="0" x:Name="textRotation"/>
</TransformGroup>
</TextBlock.RenderTransform>
在代码隐藏中:
_ani = new DoubleAnimation(0, 360, TimeSpan.FromSeconds(5));
_ani.AutoReverse = false;
_ani.RepeatBehavior = RepeatBehavior.Forever;
textRotation.BeginAnimation(RotateTransform.AngleProperty, _ani);
试试这个
<TextBlock x:Name="status_1" HorizontalAlignment="Right" Margin="288,95,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" FontFamily="/InstallerPanes;component/App_Plugins/FontAwesomeIconsDD/assets/font-awesome/fonts/#FontAwesome" Visibility="Visible" RenderTransformOrigin="0.5,0.5">
<TextBlock.RenderTransform>
<RotateTransform Angle="0"/>
</TextBlock.RenderTransform>
</TextBlock>