【发布时间】:2011-04-15 01:27:50
【问题描述】:
我已经通过以下方式实现了网格控件的移动动画:
<Grid
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.Style>
<Style TargetType="Grid">
<Style.Triggers>
<DataTrigger
Binding="{Binding ElementName=rootLayout, Path=IsVisible}"
Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ThicknessAnimation
Storyboard.TargetProperty="Margin"
From="-500,0,0,0"
To="0,0,0,0"
Duration="0:0:0.5" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<Border
Grid.RowSpan="2"
Background="Black"
CornerRadius="6" >
<Border.Effect>
<DropShadowEffect />
</Border.Effect>
</Border>
<TextBlock
Grid.Row="0"
Width="400"
Height="200"
Margin="20,20,20,10"
Text="{Binding Path=MessageText}" />
<Button
Grid.Row="1"
Margin="20,5,20,15"
HorizontalAlignment="Right"
Width="75"
Content="OK"
Command="{Binding Path=CloseDialogCommand}" />
</Grid>
动画效果很好,但很丑。它摇摇欲坠/紧张不安/生涩,看起来真的不专业。有没有办法改善这一点?我是否使用正确的方法为Margin 属性上的值更改设置动画以移动网格?我读过RenderTransform,但我不知道如何在我的情况下使用它。
此外,动画看起来不自然。我知道这可以改进,但我不知道如何。这些属性是什么?它们可以帮助我增强动画效果吗:
AccelerationRatioDecelerationRatioEasingFunctionIsAdditiveIsCumulative-
SpeedRatio
感谢您的帮助!
附:我正在尝试在 XAML 中放置尽可能多的代码,所以我更喜欢这种方法,但实际上,如果有什么可以改进的......
【问题讨论】: