我刚刚在xaml中的Storyboard中创建了一个运动路径,并注意到,如果我调整窗口的大小或将其设置为最大尺寸,则由Ellipse设置要进行轨道运动的矩形所设置的运动路径仍会像窗口的大小一样工作不会影响它。
我尝试使矩形响应,但这仅对尺寸有效,对路径无效。
<Page.Resources>
<Storyboard x:Key="orbit_planet">
<DoubleAnimationUsingPath Duration="0:0:4" Source="X"
Storyboard.TargetProperty="(UIElement.RenderTransform).
(TransformGroup.Children)[3].(TranslateTransform.X)"
Storyboard.TargetName="rectangle" RepeatBehavior="Forever">
<DoubleAnimationUsingPath.PathGeometry>
<PathGeometry Figures="M498.5,-45.25 C498.5,13.568326
405.15137,61.25 290,61.25 C174.84863,61.25 81.5,13.568326 81.5,-45.25
C81.5,-104.06833 174.84863,-151.75 290,-151.75 C405.15137,-151.75
498.5,-104.06833 498.5,-45.25 z"/>
</DoubleAnimationUsingPath.PathGeometry>
</DoubleAnimationUsingPath>
<DoubleAnimationUsingPath Duration="0:0:4" Source="Y"
Storyboard.TargetProperty="(UIElement.RenderTransform).
(TransformGroup.Children)[3].(TranslateTransform.Y)"
Storyboard.TargetName="rectangle" RepeatBehavior="Forever">
<DoubleAnimationUsingPath.PathGeometry>
<PathGeometry Figures="M498.5,-45.25 C498.5,13.568326
405.15137,61.25 290,61.25 C174.84863,61.25 81.5,13.568326 81.5,-45.25
C81.5,-104.06833 174.84863,-151.75 290,-151.75 C405.15137,-151.75
498.5,-104.06833 498.5,-45.25 z"/>
</DoubleAnimationUsingPath.PathGeometry>
</DoubleAnimationUsingPath>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="
(UIElement.RenderTransform).(TransformGroup.Children)[0].
(ScaleTransform.ScaleX)" Storyboard.TargetName="rectangle">
<EasingDoubleKeyFrame KeyTime="0" Value="0.7"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.8"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="0.9"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.3" Value="0.9"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.6" Value="0.8"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="0.7"/>
<EasingDoubleKeyFrame KeyTime="0:0:2.3" Value="0.6"/>
<EasingDoubleKeyFrame KeyTime="0:0:2.6" Value="0.5"/>
<EasingDoubleKeyFrame KeyTime="0:0:3" Value="0.4"/>
<EasingDoubleKeyFrame KeyTime="0:0:3.3" Value="0.5"/>
<EasingDoubleKeyFrame KeyTime="0:0:3.6" Value="0.6"/>
<EasingDoubleKeyFrame KeyTime="0:0:4" Value="0.7"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="
(UIElement.RenderTransform).(TransformGroup.Children)[0].
(ScaleTransform.ScaleY)" Storyboard.TargetName="rectangle">
<EasingDoubleKeyFrame KeyTime="0" Value="0.7"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.8"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="0.9"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.3" Value="0.9"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.6" Value="0.8"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="0.7"/>
<EasingDoubleKeyFrame KeyTime="0:0:2.3" Value="0.6"/>
<EasingDoubleKeyFrame KeyTime="0:0:2.6" Value="0.5"/>
<EasingDoubleKeyFrame KeyTime="0:0:3" Value="0.4"/>
<EasingDoubleKeyFrame KeyTime="0:0:3.3" Value="0.5"/>
<EasingDoubleKeyFrame KeyTime="0:0:3.6" Value="0.6"/>
<EasingDoubleKeyFrame KeyTime="0:0:4" Value="0.7"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Page.Resources>
<Page.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource orbit_planet}"/>
</EventTrigger>
</Page.Triggers>
<Grid>
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="White"/>
</LinearGradientBrush>
</Grid.Background>
<Ellipse Margin="181.5,130.5,200.5,105.5" Stroke="Black"/>
<Rectangle x:Name="rectangle" HorizontalAlignment="Left" Height="100"
Margin="54,0,0,126" Stroke="Black" VerticalAlignment="Bottom" Width="100"
RenderTransformOrigin="0.5,0.5">
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Rectangle.RenderTransform>
<Rectangle.Fill>
<ImageBrush ImageSource="Images/apple.png"/>
</Rectangle.Fill>
</Rectangle>
</Grid>
</Page>
我想通过窗口大小影响路径。 这只能在xaml中实现吗?