WPF panel slide in from left animation

梦想的初衷 提交于 2019-12-07 08:10:31

问题


I'm trying to get a Panel to animate a sliding in behavior in WPF. I'm new to animations and am having some trouble. The panel with fills from the center out rather than from the left and it only animates the first time. I know I'm doing something wrong so any help would be appreciated. Below is the markup for my animation.

<Style.Triggers>
        <Trigger  Property="Visibility" Value="Visible">
            <Trigger.EnterActions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation From="0" To="200" Duration="0:0:0.5"
                                         AccelerationRatio="0.2" DecelerationRatio="0.1"
                                         Storyboard.TargetProperty="Width"/>
                    </Storyboard>
                </BeginStoryboard>
            </Trigger.EnterActions>
        </Trigger>
    </Style.Triggers>

回答1:


Don't animate properties like "Width", that is what RenderTransforms are for.

To get the behavior you describe ("Sliding in") you want to animate a TranslateTransform from some X off the screen/page to the final position.

To get the behavior your XAML and the rest of your post indicates, you would use a ScaleTransform with the origin set to the left hand side of the panel.

You should also know that the targeting of render transforms can be a little tricky, see this question for more information

Here is the documentation for RenderTransforms (MSDN)



来源:https://stackoverflow.com/questions/22330837/wpf-panel-slide-in-from-left-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!