luckapple2

wpf利用动画实现图形变化产生3d效果.

12.25

     利用动画animation实现图形变换。这里实现了7个动画变换图形。可以附加起来一起使用。
也可以单独使用。这里每个图形变换的中心是控件中心,可以根据自己需求更改。可以平移,可以旋转,显示wpf3d效果。 TranslateTransform,ScaleTransform,SkewTransform,RotateTransform几个图形变换是RenderTransform的子property.之所以用RenderTransform而不用LayoutTransform是因为LayoutTransform忽略平移变换。对elemenet的位置没有任何影响。LayoutTransform内任何改变都会从新layout,所以控件不可能出现重叠。RenderTransform里要是布局发生变化,就会自动重叠,后load再上面。
  <Canvas>
        <TextBlock Text="XAML" FontSize="44pt" FontFamily="Arial Black" RenderTransformOrigin="0.5,0.5">
            <TextBlock.RenderTransform>
                <TransformGroup>
                <ScaleTransform x:Name="xformScale"/>
                    <ScaleTransform x:Name="xformScale2"/>
                <RotateTransform x:Name="xformRotate"/>
                    <SkewTransform x:Name="xformSkew"/>
                    <SkewTransform x:Name="xformSkew2"/>
                    <TranslateTransform x:Name="xformTrans"/>
                    <TranslateTransform x:Name="xformTrans2"/>
                </TransformGroup>
            </TextBlock.RenderTransform>
            <TextBlock.Triggers>
                <EventTrigger RoutedEvent="TextBlock.Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <!--沿x轴变成0宽度-->
                            <!--<DoubleAnimation Storyboard.TargetName="xformScale" Storyboard.TargetProperty="ScaleX"
                                             From="1" To="0" Duration="0:0:5" AutoReverse="True" RepeatBehavior="Forever"/>-->
                           <!--沿Y轴变成0宽度-->
                            <!--<DoubleAnimation Storyboard.TargetName="xformScale2" Storyboard.TargetProperty="ScaleY"
                                             From="1" To="0" Duration="0:0:5" AutoReverse="True" RepeatBehavior="Forever"/>-->  
                           <!--360度旋转-->
                            <!--<DoubleAnimation Storyboard.TargetName="xformRotate" Storyboard.TargetProperty="Angle"
                                             From="0" To="360" Duration="0:0:5" RepeatBehavior="Forever"/>-->
                            <!--向无穷远处消失成一条y轴-->
                            <!--<DoubleAnimation Storyboard.TargetName="xformSkew" Storyboard.TargetProperty="AngleY"
                                             From="0" To="90" Duration="0:0:5" RepeatBehavior="Forever"/>-->
                            <!--向无穷远处消失成一条x轴-->
                            <!--<DoubleAnimation Storyboard.TargetName="xformSkew2" Storyboard.TargetProperty="AngleX"
                                             From="0" To="90" Duration="0:0:5" RepeatBehavior="Forever"/>-->
                            <!--沿x轴平移-->
                            <DoubleAnimation Storyboard.TargetName="xformTrans" Storyboard.TargetProperty="X"
                                             From="0" To="200" Duration="0:0:5" RepeatBehavior="Forever"/>
                            <!--沿y轴平移-->
                            <DoubleAnimation Storyboard.TargetName="xformTrans2" Storyboard.TargetProperty="Y"
                                             From="0" To="200" Duration="0:0:5" RepeatBehavior="Forever"/>      
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </TextBlock.Triggers>  
        </TextBlock>
    </Canvas>

posted on 2008-12-25 21:47  luckapple2  阅读(2854)  评论(1编辑  收藏  举报

导航