我正在尝试为即将到来的项目熟悉 WPF。我在为状态之间的边距设置动画时遇到问题。使用 Blend,我获得了以下示例 XAML。如果我从代码隐藏触发状态“大”,矩形会在 1 秒后突然扩展,而不是“缓和”到扩展中,这是预期的效果。
<Grid x:Name="LayoutRoot">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisualStateGroup">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:1"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="Large">
<Storyboard>
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="rectangle">
<EasingThicknessKeyFrame KeyTime="0" Value="64,135,47,191"/>
</ThicknessAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle x:Name="rectangle" Fill="#FFF4F4F5" Margin="428,135,47,191" Stroke="Black"/>
</Grid>
提前致谢!