首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

WPF中PropertyPath疑点

2012-09-22 
WPF中PropertyPath疑问我想在点击一个按钮的时候对一个image进行一个动画效果,就是把他略微放大再还原,代

WPF中PropertyPath疑问
我想在点击一个按钮的时候对一个image进行一个动画效果,就是把他略微放大再还原,代码如下:
前台:

XML code
<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>


后台:
C# code
 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();        }



从代码可以看到,因为有一堆图片放在WrapPanel下,我要的效果只是放大其中一个图片,且不能影响其他元素的布局,所以我的做法是同时改变image的Height,Width还有Margin,但是Margin这个东西是Thickness类型的,我的目的是要改变Margin里面的Left,Right,Bottom,Top,请问这些属性如何绑定到PropertyPath,使动画可以成功跑起??请各位高人赐教,在下不胜感激!!!

[解决办法]
自问自答???
我也有个弱弱的问题
就是 new PropertyPath("Margin") 是啥意思???
把Margin对象作为字符串属性???
不懂??

热点排行