日期:2014-05-18 浏览次数:21061 次
<Window.Resources> <Storyboard x:Key="sboard"> <DoubleAnimation Storyboard.TargetName="ttXaml" Storyboard.TargetProperty="X" Duration="00:00:01" From="0" To="30" /> </Storyboard> </Window.Resources> <Grid> <Button x:Name="button1" Content="click" Click="button1_Click" Width="50" Height="50"> <Rectangle.RenderTransform> <TranslateTransform x:Name="ttXaml"/> </Rectangle.RenderTransform> </Button> </Grid>
(this.Resources["sboard"] as Storyboard).Begin();
TranslateTransform tt = new TranslateTransform(); // RotateTransform rt = new RotateTransform(); this.button1.RenderTransform = tt; this.button1.Name = "button1"; NameScope.SetNameScope(this, new NameScope()); this.RegisterName(this.button1.Name, this.button1); DoubleAnimation xAnimation = new DoubleAnimation(); xAnimation.From = 0; xAnimation.To = 100; xAnimation.Duration = new Duration(TimeSpan.FromSeconds(1)); DependencyProperty[] propertyChain = new DependencyProperty[] // 使用属性链的时候应用 { Button.RenderTransformProperty, TranslateTransform.XProperty, RotateTransform.AngleProperty // 调整角度时候用 }; Storyboard story = new Storyboard(); // story.AutoReverse = true; // story.RepeatBehavior = RepeatBehavior.Forever; story.Children.Add(xAnimation); //Storyboard.SetTargetName(xAnimation, this.button1.Name); //Storyboard.SetTargetProperty(xAnimation, new PropertyPath("(0).(1)", propertyChain)); Storyboard.SetTarget(xAnimation, tt); Storyboard.SetTargetProperty(xAnimation, new PropertyPath(TranslateTransform.XProperty)); //Storyboard.SetTarget(xAnimation, rt); //Storyboard.SetTargetProperty(xAnimation, new PropertyPath(RotateTransform.AngleProperty)); story.Begin(this);