简体   繁体   中英

WPF codebehind animation c#

Can anyone help me how to create an animation thru codebehind using an that will take a motion using a defined controls?

please dont closed this i really need help on this....

<Image x:Name="imgMan" Source="/wpfUsrControlTower1;component/DependentResources/man.png" Stretch="Fill" Height="26.4">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>

<Path x:Name="k3_r2" Visibility="Hidden" Fill="Transparent" StrokeThickness="3" StrokeDashArray="2 0 0 2" Stretch="Fill" Stroke="Blue" Data="M570,190 L570,160 495,160 495,125 165,125 165,175" Height="65" Canvas.Left="165" Canvas.Top="125" Width="405"/>

With a MatrixTransform as the Image's RenderTransform

<Canvas>
    <Path x:Name="k3_r2"
          StrokeThickness="3" StrokeDashArray="4 4" Stroke="Blue"
          Data="M570,190 L570,160 495,160 495,125 165,125 165,175"/>

    <Image x:Name="imgMan"
           Source="/wpfUsrControlTower1;component/DependentResources/man.png"
           Stretch="Fill" Height="30"
           Canvas.Left="-15" Canvas.Top="-15">
        <Image.RenderTransform>
            <MatrixTransform/>
        </Image.RenderTransform>
    </Image>
</Canvas>

you may use something like this:

var animation = new MatrixAnimationUsingPath
{
    PathGeometry = PathGeometry.CreateFromGeometry(k3_r2.Data),
    Duration = TimeSpan.FromSeconds(5)
};

imgMan.RenderTransform.BeginAnimation(MatrixTransform.MatrixProperty, animation);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM