微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Silverlight滑动动画

话说对于刚刚学习SL的人来说,特别是从HTML跳过来 玩动画的时候 那边的思路很多不通的,在SL里面的滑动直接更换Margin不行,后面慢慢摸索才弄出来 的 希望对大家有帮助

 

目前只是写了一步,以后可以根据自己扩展

Dome

http://download.csdn.net/detail/qq873113580/5993237

前台

<Grid x:Name="LayoutRoot" Background="White">
        <Grid Background="AliceBlue" HorizontalAlignment="Left" Height="100" Margin="206,47,0" VerticalAlignment="Top" Width="400">
            <StackPanel x:Name="spImages" Orientation="Horizontal" VerticalAlignment="Stretch" Width="900">
                <StackPanel.RenderTransform>
                    <TransformGroup>
                        <TranslateTransform X="0"></TranslateTransform>
                    </TransformGroup>
                </StackPanel.RenderTransform>
                <Image Width="100" Height="100" Source="Image/1.jpg" Stretch="Fill"/>
                <Image Width="100" Height="100" Source="Image/2.jpg" Stretch="Fill"/>
                <Image Width="100" Height="100" Source="Image/3.jpg" Stretch="Fill"/>
                <Image Width="100" Height="100" Source="Image/4.jpg" Stretch="Fill"/>
                <Image Width="100" Height="100" Source="Image/5.jpg" Stretch="Fill"/>
                <Image Width="100" Height="100" Source="Image/6.jpg" Stretch="Fill"/>
                <Image Width="100" Height="100" Source="Image/7.jpg" Stretch="Fill"/>
                <Image Width="100" Height="100" Source="Image/8.jpg" Stretch="Fill"/>
                <Button Content="Button" Width="75"/>
            </StackPanel>
        </Grid>
        <Button Content="上一张" HorizontalAlignment="Left" Margin="531,181,0" VerticalAlignment="Top" Width="75"/>
        <Button Content="下一张" HorizontalAlignment="Left" Margin="206,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
    </Grid>


 

后台

private void Button_Click_1(object sender,RoutedEventArgs e)
        {
            Storyboard storyBoard = new Storyboard();
            //设置动画轨迹
            DoubleAnimation doubleAnimation = new DoubleAnimation();
            //执行时间
            doubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(500));
            //变量大小
            doubleAnimation.To = -100;
            //绑定执行动画的对象
            Storyboard.SetTarget(doubleAnimation,this.spImages);
            //设置执行动画的属性
            Storyboard.SetTargetProperty(doubleAnimation,new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)"));
            //添加动画
            storyBoard.Children.Add(doubleAnimation);
            //执行动画
            storyBoard.Begin();
        }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐