話說對於剛剛學習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(); }