0

iv'e 有一个 ToggleButton,它在“已检查”状态下包含一个多边形,我将多边形旋转 90 度。

问题是在旋转完成后,多边形会弹回到它的初始角度。

我的切换按钮:(部分模板)

    <ControlTemplate TargetType="{x:Type ToggleButton}">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="FocusStates">
                <VisualState x:Name="Unfocused"/>
                <VisualState x:Name="Focused"/>
            </VisualStateGroup>
            <VisualStateGroup x:Name="CommonStates">
                <VisualStateGroup.Transitions>
                   <VisualTransition GeneratedDuration="00:00:00.3"/>                               
                </VisualStateGroup.Transitions>
                <VisualState x:Name="MouseOver"/>
                <VisualState x:Name="Normal"/>
                <VisualState x:Name="Pressed"/>
                <VisualState x:Name="Disabled"/>
            </VisualStateGroup>
            <VisualStateGroup x:Name="CheckStates">
                <VisualStateGroup.Transitions>
                   <VisualTransition GeneratedDuration="0" To="Checked">
                    <Storyboard>                                            
                       <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="regularPolygon">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="90" />
                       </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualTransition>                                                
                    <VisualState x:Name="Indeterminate"/>
                    <VisualState x:Name="Checked"/>
                    <VisualState x:Name="Unchecked"/>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>                     
                <Polygon x:Name="regularPolygon" 
                    Points="5,10 10,5 5,0"
                    RenderTransformOrigin="0.5,0.5" 
                    Stretch="Fill"                          
                    UseLayoutRounding="False">
                     <Polygon.RenderTransform>
                      <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform />
                        <TranslateTransform/>
                          </TransformGroup>
                     </Polygon.RenderTransform>                        
                </Polygon>                                          
            </ControlTemplate>

我是否需要进行一些更改以使多边形保持新的角度?提前致谢 。

4

1 回答 1

0

问题是我将动画放置在过渡中而不是状态本身

  <VisualState x:Name="Checked">
     <Storyboard>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Angle" Storyboard.TargetName="rotateTransform">
             <EasingDoubleKeyFrame KeyTime="0:0:0.7" Value="90"/>
        </DoubleAnimationUsingKeyFrames>
      </Storyboard>
   </VisualState>
于 2013-08-12T09:01:22.017 回答