Silverlight滑动动画

来源:互联网 发布:opencv算法精解 编辑:程序博客网 时间:2024/05/02 08:21

话说对于刚刚学习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();        }


 

原创粉丝点击