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,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,0" VerticalAlignment="Top" Width="75"/>
        <Button Content="下一张" HorizontalAlignment="Left" Margin="206,181,0,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();
        }


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值