locked
Re sizing an animation as the form is re sized RRS feed

  • Question

  • I have a canvas which auto sizes with the form, when a button is clicked i want the Canvas to fly of the screen to the left. so far my animation works at the original resolution but when the form (and canvas) are re sized the canvas will then only partially move off the screen.

    Please Help, Tim.

    Sunday, December 2, 2012 1:13 PM

All replies

  • Hello Tim.

    You could try to create your own animation in code-behind...

    private void button_Click(object sender, System.Windows.RoutedEventArgs e)
    		{
    			TranslateTransform tt = new TranslateTransform();
    			canvas.RenderTransform = tt;
    			
    			DoubleAnimation da = new DoubleAnimation();
    			da.Duration = new Duration(TimeSpan.FromSeconds(3));
    			da.From = 0;
    			da.To = this.ActualWidth * -1;
    			tt.BeginAnimation(TranslateTransform.XProperty, da);
    		}

    You could also go into your xaml and change the "To" value of your storyboard and bind it to your canvas ActualWidth.

    <Storyboard x:Key="Storyboard1">
    			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="canvas2">
    				<EasingDoubleKeyFrame KeyTime="0:0:2" Value="{Binding ActualWidth, ElementName=canvas2}"/>
    			</DoubleAnimationUsingKeyFrames>
    		</Storyboard>

    In either case, if you have done the animation and the animation moved the canvas down or to the right and then you resize... the canvas will still be there and visible.  So you should remove the canvas when the animation is complete or reposition it on the window resize event. 

    Hope that gives you some ideas.

    ~Christine


    My Gallery - calControls

    Sunday, December 2, 2012 5:35 PM