Animating a fade in from left

Craig Muckleston 161 Reputation points
2020-10-14T14:06:55.957+00:00

I have the following Path:

    <Path x:Name="cameraWestPath" StrokeThickness="1" Fill="Green" RenderTransformOrigin="0.46,0.61"  Visibility="Visible" Opacity="0">
        <Path.RenderTransform>
            <CompositeTransform Rotation="315"/>
        </Path.RenderTransform>
        <Path.Data>
            <PathGeometry>
                <PathGeometry.Figures>
                    <PathFigure StartPoint="0,45" >
                        <PathFigure.Segments>
                            <ArcSegment Size="45,45" RotationAngle="45" IsLargeArc="False" SweepDirection="Clockwise" Point="45,0"/>
                            <LineSegment Point="45,45"/>
                            <LineSegment Point="0,45"/>
                        </PathFigure.Segments>
                    </PathFigure >
                </PathGeometry.Figures>
            </PathGeometry>
        </Path.Data>
    </Path>

What I want to do is fade this path in from left right in a Storyboard, but I'm not sure how I can achieve it.

Universal Windows Platform (UWP)
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,678 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Richard Zhang-MSFT 6,936 Reputation points
    2020-10-15T02:13:04.023+00:00

    Hello,

    Welcome to Microsoft Q&A.

    What I want to do is fade this path in from left right in a Storyboard, but I'm not sure how I can achieve it.

    According to your needs, the effect requires two variables to control, one is Opacity (from 0 to 1) and the other is TranslateX (from left to right)

    Here is a sample:

    PathPage.xaml

       <Page.Resources>  
           <Storyboard x:Name="PathInAnimation">  
               <DoubleAnimation From="0"  
                                To="1"  
                                Duration="00:00:00.5"  
                                Storyboard.TargetName="cameraWestPath"  
                                Storyboard.TargetProperty="Opacity"  
                                >  
                   <DoubleAnimation.EasingFunction>  
                       <PowerEase EasingMode="EaseOut"></PowerEase>  
                   </DoubleAnimation.EasingFunction>  
               </DoubleAnimation>  
               <DoubleAnimation From="-45"  
                                To="0"  
                                Duration="00:00:00.5"  
                                Storyboard.TargetName="cameraWestPath"  
                                Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)"  
                                >  
                   <DoubleAnimation.EasingFunction>  
                       <PowerEase EasingMode="EaseOut"></PowerEase>  
                   </DoubleAnimation.EasingFunction>  
               </DoubleAnimation>  
           </Storyboard>  
       </Page.Resources>  
         
       <Grid>  
           <Grid.RowDefinitions>  
               <RowDefinition Height="*"/>  
               <RowDefinition Height="Auto"/>  
           </Grid.RowDefinitions>  
           <Path x:Name="cameraWestPath" StrokeThickness="1" Fill="Green" RenderTransformOrigin="0.46,0.61"  Visibility="Visible" Opacity="0">  
               <Path.RenderTransform>  
                   <CompositeTransform TranslateX="-45" Rotation="315"/>  
               </Path.RenderTransform>  
               <Path.Data>  
                   <PathGeometry>  
                       <PathGeometry.Figures>  
                           <PathFigure StartPoint="0,45" >  
                               <PathFigure.Segments>  
                                   <ArcSegment Size="45,45" RotationAngle="45" IsLargeArc="False" SweepDirection="Clockwise" Point="45,0"/>  
                                   <LineSegment Point="45,45"/>  
                                   <LineSegment Point="0,45"/>  
                               </PathFigure.Segments>  
                           </PathFigure >  
                       </PathGeometry.Figures>  
                   </PathGeometry>  
               </Path.Data>  
           </Path>  
         
           <Button x:Name="ShowButton" Click="ShowButton_Click" Grid.Row="1"  
                   Content="Start Animation"/>  
       </Grid>  
    

    PathPage.xaml.cs

       private void ShowButton_Click(object sender, RoutedEventArgs e)  
       {  
           PathInAnimation.Begin();  
       }  
    

    Thanks.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments