酒伴不如久伴
2017-11-24 01:24
采纳率: 33.3%
浏览 1.7k
已采纳

WPF使用动画如何实现抽屉效果

wpf的写法一个Grid包另一个Grid,里面的Grid定宽,外面的动画实现一点点缩小,实现一个抽屉效果,求给个代码,急用

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • APPLYI 2017-12-21 09:03
    已采纳

    是从左到右推出来的那种抽屉动画吗?

     <Window.Resources>
            <Storyboard x:Key="STORYBOARD_SHOW">
                <ThicknessAnimation To="0,0,0,0" Duration="0:0:0.7" Storyboard.TargetName="grdDrawer" Storyboard.TargetProperty="Margin">
                    <ThicknessAnimation.EasingFunction>
                        <CubicEase EasingMode="EaseOut"></CubicEase>
                    </ThicknessAnimation.EasingFunction>
                </ThicknessAnimation>
            </Storyboard>
            <Storyboard x:Key="STORYBOARD_HIDE">
                <ThicknessAnimation To="-200,0,0,0" Duration="0:0:0.7" Storyboard.TargetName="grdDrawer" Storyboard.TargetProperty="Margin">
                    <ThicknessAnimation.EasingFunction>
                        <CubicEase EasingMode="EaseOut"></CubicEase>
                    </ThicknessAnimation.EasingFunction>
                </ThicknessAnimation>
            </Storyboard>
        </Window.Resources>
        <Grid ClipToBounds="True">
            <Grid x:Name="grdDrawer" Width="200" Margin="0,0,0,0" HorizontalAlignment="Left" Background="DimGray" >
                <Grid x:Name="grdContainer" Width="200">
                        <TextBlock><Run Text="CONTAINER1" Foreground="White"></Run></TextBlock>
                </Grid>
            </Grid>
        </Grid>
    

    执行的话用下面的CS语言

    /*打开*/
     var storyboard = (Storyboard)FindResource("STORYBOARD_SHOW");
     storyboard.Begin();
     /*关闭*/
     var storyboard = (Storyboard)FindResource("STORYBOARD_HIDE");
    storyboard.Begin();
    
    点赞 打赏 评论

相关推荐 更多相似问题