大佬教程收集整理的这篇文章主要介绍了wpf – 当左边距变为负时,动画减慢,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经得到了这个工作.但是,由于某种原因,一旦左边距变为负值,动画就会突然减慢.一旦左边距变为正值,它将再次加速.
为什么会发生这种情况?我该如何阻止?
以下是完整的代码:
<Window x:Class="Geometry.MainWindow" xmlns="http://scheR_237_11845@as.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://scheR_237_11845@as.microsoft.com/winfx/2006/xaml" title="MainWindow" Height="350" Width="525"> <Window.resources> <PathGeometry x:Key="MyGeometry"> <PathGeometry.Figures> <PathFigure> <PathFigure.Segments> <Linesegment Point="0.30,0" /> <Linesegment Point="0.70,1" /> <Linesegment Point="0.40,1" /> <Linesegment Point="0,0" /> </PathFigure.Segments> </PathFigure> </PathGeometry.Figures> </PathGeometry> <Storyboard x:Key="MovingAnimation"> <ThicknessAnimationUsingKeyFrames RepeatBehavior="1:0:0" FillBehavior="HoldEnd" Storyboard.TargetName="_path" Storyboard.TargetProperty="Margin" > <DiscreteThicknessKeyFrame KeyTime="0:0:0" Value="-2.0,0" /> <LinearThicknessKeyFrame KeyTime="0:0:10" Value="1.0,0" /> <LinearThicknessKeyFrame KeyTime="0:0:20" Value="-2.0,0" /> </ThicknessAnimationUsingKeyFrames> </Storyboard> </Window.resources> <Window.triggers> <Eventtrigger RoutedEvent="Window.Loaded"> <BeginStoryboard Storyboard="{Staticresource MovingAnimation}" ></BeginStoryboard> </Eventtrigger> </Window.triggers> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <StackPanel Grid.Row="0" Orientation="Horizontal"> <Label>Margin:</Label> <TextBlock Text="{Binding ElementName=_path,Path=Margin.Left,StringFormat={}{0:0.#}}" /> </StackPanel> <Canvas Name="_canvas" Grid.Row="1"> <Border Margin="0" Width="1" Height="1" VerticalAlignment="Center" HorizontalAlignment="Center"> <Border.RenderTransform> <ScaleTransform ScaleX="{Binding ElementName=_canvas,Path=ActualWidth}" ScaleY="{Binding ElementName=_canvas,Path=ActualHeight}" CenterX="0" CenterY="0"> </ScaleTransform> </Border.RenderTransform> <Path Name="_path" Fill="#CCCCFF" Data="{Staticresource MyGeometry}" Width="1.0" Height="1.0" > </Path> </Border> </Canvas> </Grid> </Window>
请,看看有点简单的方法做什么,我想,你想得到:
<Window x:Class="Geometry.MainWindow" xmlns="http://scheR_237_11845@as.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://scheR_237_11845@as.microsoft.com/winfx/2006/xaml" title="MainWindow" Height="518" Width="530"> <Window.resources> <PathGeometry x:Key="MyGeometry"> <PathGeometry.Figures> <PathFigure> <PathFigure.Segments> <Linesegment Point="0.30,0" /> <Linesegment Point="0.70,1" /> <Linesegment Point="0.40,1" /> <Linesegment Point="0,0" /> </PathFigure.Segments> </PathFigure> </PathGeometry.Figures> </PathGeometry> <Storyboard x:Key="MovingAnimation"> <DoubleAnimationUsingKeyFrames RepeatBehavior="1:0:0" FillBehavior="HoldEnd" Storyboard.TargetName="_scaleTransform" Storyboard.TargetProperty="CenterX" > <LinearDoubleKeyFrame KeyTime="0:0:0" Value="1.2" /> <LinearDoubleKeyFrame KeyTime="0:0:10" Value="-0.5" /> <LinearDoubleKeyFrame KeyTime="0:0:20" Value="1.2" /> </DoubleAnimationUsingKeyFrames> </Storyboard> </Window.resources> <Window.triggers> <Eventtrigger RoutedEvent="Window.Loaded"> <BeginStoryboard Storyboard="{Staticresource MovingAnimation}" ></BeginStoryboard> </Eventtrigger> </Window.triggers> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <StackPanel Grid.Row="0" Orientation="Horizontal"> <Label>Margin:</Label> <TextBlock Text="{Binding ElementName=_scaleTransform,Path=CenterX,StringFormat={}{0:0.#}}" VerticalAlignment="Center" /> </StackPanel> <!-- <Border Grid.Row="1" Margin="150" BorderBrush="Red" BorderThickness="1"> --> <Grid Name="_canvas" Grid.Row="1"> <Path Name="_path" Fill="#CCCCFF" Data="{Staticresource MyGeometry}" Width="1.0" Height="1.0" HorizontalAlignment="Center" VerticalAlignment="Center"> <Path.RenderTransform> <ScaleTransform x:Name="_scaleTransform" ScaleX="{Binding ElementName=_canvas,Path=ActualHeight}" CenterX="1.2" CenterY="0.5"> </ScaleTransform> </Path.RenderTransform> </Path> </Grid> <!-- </Border> --> </Grid> </Window>
以上是大佬教程为你收集整理的wpf – 当左边距变为负时,动画减慢全部内容,希望文章能够帮你解决wpf – 当左边距变为负时,动画减慢所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。