WPF Animated Animation - Why Can't By By Have Negative Value?

I am animating in WPF and I'm confused. For RectAnimation, By cannot be negative in height and width.

So, if you use the keyword β€œBy”, can the rectangles only grow (instead of β€œTo”)?

Here is a sample code:

<Page  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
  <StackPanel Orientation="Vertical" HorizontalAlignment="Left">
    <Path Stroke="Black" StrokeThickness="1" Fill="LemonChiffon">
      <Path.Data>
        <RectangleGeometry x:Name="myRectangleGeometry" Rect="0,200,100,100" />

      </Path.Data>
      <Path.Triggers>
        <EventTrigger RoutedEvent="Path.Loaded">
          <BeginStoryboard>
            <Storyboard> 
              <!-- Animate the Rect property of the RectangleGeometry
                   which causes the rectangle to animate postion and size. -->
              <RectAnimation
              Storyboard.TargetName="myRectangleGeometry"
              Storyboard.TargetProperty ="Rect"
              Duration="0:0:2" FillBehavior="HoldEnd" 
              From="0,0,100,100"
              By="600,50,200,-50" />
                               ^
            </Storyboard>      |
          </BeginStoryboard>   |
        </EventTrigger>        |
      </Path.Triggers>         |
    </Path>                    |
  </StackPanel>                |
</Page>                        |
                               |
This returns an error, but only if it is negative.
+3
source share
1 answer

In fact, you define a rectangle in the property Byof the RectAnimation object. Unable to create a rectangle with negative dimensions.

By="x,y,Width,Height"

What you probably want to do can be done using the property To:

To="600,50,300,50"

+3
source

Source: https://habr.com/ru/post/1725670/


All Articles