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

WPF中怎么用Storyboard

2012-11-04 
WPF中如何用StoryboardXML codeStoryboard x:KeyStoryboard1DoubleAnimationUsingKeyFrames Storybo

WPF中如何用Storyboard

XML code
<Storyboard x:Key="Storyboard1"><DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="grid"><EasingDoubleKeyFrame KeyTime="0" Value="1"/><EasingDoubleKeyFrame KeyTime="0:0:1" Value="-1"/><EasingDoubleKeyFrame KeyTime="0:0:2" Value="-1"/></DoubleAnimationUsingKeyFrames></Storyboard>


上面是在Blend中做好的一段翻转动画代码,想在后台动态定义,该如何写呢?
似乎和SL不太一样,在SL里的方式,拿到WPF中就会报错

C# code
Storyboard keyFrameboard = new Storyboard();            DoubleAnimationUsingKeyFrames dakeyframe = new DoubleAnimationUsingKeyFrames();            Storyboard.SetTarget(dakeyframe, icCurrent);            Storyboard.SetTargetProperty(dakeyframe, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"));            dakeyframe.BeginTime = new TimeSpan(0, 0, 0);            EasingDoubleKeyFrame edKeyFrame = new EasingDoubleKeyFrame();            edKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1));            edKeyFrame.Value = -1;            dakeyframe.KeyFrames.Add(edKeyFrame);            keyFrameboard.Children.Add(dakeyframe);            keyFrameboard.Begin();


上面是我的写法,但报如下错误:

Cannot resolve all property references in the property path '(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)'. Verify that applicable objects support the properties.

请高手指教!!!

[解决办法]
路过,帮顶下
[解决办法]
看了你的代码,还是因为没有定义

要让自定义控件进行旋转变换,需要对自定义控件的转换进行定义,你在自定义控件里面定义的转变,在mainwindow中找不到的

正确方法如下,有两种:

一、xaml方式
HTML code
     <Canvas x:Name="canvasBottom" Width="500" Height="500" Background="Gray" Grid.Row="1">      <my:ImageContainer x:Name="ic" Width="200" Height="200" >        <my:ImageContainer.RenderTransform>          <TransformGroup>            <ScaleTransform/>            <SkewTransform/>            <RotateTransform/>            <TranslateTransform/>          </TransformGroup>        </my:ImageContainer.RenderTransform>      </my:ImageContainer>    </Canvas> 

热点排行