WPF中PropertyPath疑问
我想在点击一个按钮的时候对一个image进行一个动画效果,就是把他略微放大再还原,代码如下:
前台:
<WrapPanel> <Image Name="img1" Margin="10" Height="130" Width="130" Source="/WpfApplication1;component/Images/aa.jpg" Stretch="Uniform"/> <Image Name="img2" Margin="10" Height="130" Width="130" Source="/WpfApplication1;component/Images/aa.jpg" Stretch="Uniform"/> <Image Name="img3" Margin="10" Height="130" Width="130" Source="/WpfApplication1;component/Images/aa.jpg" Stretch="Uniform"/> <Image Name="img4" Margin="10" Height="130" Width="130" Source="/WpfApplication1;component/Images/aa.jpg" Stretch="Uniform"/> <Image Name="img5" Margin="10" Height="130" Width="130" Source="/WpfApplication1;component/Images/aa.jpg" Stretch="Uniform"/> <Image Name="img6" Margin="10" Height="130" Width="130" Source="/WpfApplication1;component/Images/aa.jpg" Stretch="Uniform"/> <Image Name="img7" Margin="10" Height="130" Width="130" Source="/WpfApplication1;component/Images/aa.jpg" Stretch="Uniform"/> </WrapPanel>
private void button1_Click(object sender, RoutedEventArgs e) { Storyboard storyboard = new Storyboard(); DoubleAnimationUsingKeyFrames daufs_w = new DoubleAnimationUsingKeyFrames(); daufs_w.KeyFrames.Add(new LinearDoubleKeyFrame(140, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)))); daufs_w.KeyFrames.Add(new LinearDoubleKeyFrame(130, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(1000)))); DoubleAnimationUsingKeyFrames daufs_h = new DoubleAnimationUsingKeyFrames(); daufs_h.KeyFrames.Add(new LinearDoubleKeyFrame(140, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)))); daufs_h.KeyFrames.Add(new LinearDoubleKeyFrame(130, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(1000)))); DoubleAnimationUsingKeyFrames daufs_margin = new DoubleAnimationUsingKeyFrames(); daufs_margin.KeyFrames.Add(new LinearDoubleKeyFrame(5, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500)))); daufs_margin.KeyFrames.Add(new LinearDoubleKeyFrame(10, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(1000)))); Storyboard.SetTarget(daufs_w, img2); Storyboard.SetTarget(daufs_h, img2); Storyboard.SetTargetProperty(daufs_w, new PropertyPath("Width")); Storyboard.SetTargetProperty(daufs_h, new PropertyPath("Height")); storyboard.Children.Add(daufs_w); storyboard.Children.Add(daufs_h); Storyboard.SetTarget(daufs_margin, img2); //下面的代码有问题 //Storyboard.SetTargetProperty(daufs_margin, new PropertyPath("Margin.Left")); //Storyboard.SetTargetProperty(daufs_margin, new PropertyPath("Margin/Right")); //Storyboard.SetTargetProperty(daufs_margin, new PropertyPath("Margin/Top")); //Storyboard.SetTargetProperty(daufs_margin, new PropertyPath("Margin/Bottom")); //storyboard.Children.Add(daufs_margin); if (!Resources.Contains("da")) { Resources.Add("da", storyboard); } storyboard.Begin(); }