某一天,有位兄弟问起,怎么在wpf 中做窗体的旋转放大,缩小的效果,当自己写了如下代码后,才发觉,很是怪异。。

 

<Window x:Class="WpfWindowTransform.Window2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window2" Height="300" Width="300"  x:Name="Windows2" Background="Yellow" RenderTransformOrigin="0.5,0.5"
        WindowStartupLocation="CenterScreen"  ResizeMode="NoResize" ShowInTaskbar="False">
    <Window.RenderTransform>
        <TransformGroup>
            <ScaleTransform ScaleX="1" ScaleY="1"/>
            <SkewTransform AngleX="0" AngleY="0"/>
            <RotateTransform Angle="0"/>
            <TranslateTransform X="0" Y="0"/>
        </TransformGroup>
    </Window.RenderTransform>
    <Window.Resources>
        <Storyboard x:Key="ScaleXStoryboard">
            <DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" BeginTime="00:00:00" Storyboard.TargetName="Windows2" 
                                                   Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
                <SplineDoubleKeyFrame KeyTime="00:00:03" Value="360"></SplineDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Windows2"
                                                   Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
                <SplineDoubleKeyFrame KeyTime="00:00:03" Value="0.1"></SplineDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Windows2"
                                                   Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
                <SplineDoubleKeyFrame KeyTime="00:00:03" Value="0.1"></SplineDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </Window.Resources>
    <Window.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard Storyboard="{StaticResource ScaleXStoryboard}"> 
            </BeginStoryboard>
        </EventTrigger>
    </Window.Triggers>
   
    <Grid Background="Red" Width="200" Height="200">
       
    </Grid>
</Window>

 

执行这个程序,可以看出,最终旋转效果,并非包括window的外面的部分,既 window上的标题栏,按钮等,并不会跟着旋转。。旋转的只是window窗体的内容部分!。。。。。。。。。。

 

当然,如果加上 WindowStyle="None" AllowsTransparency="True"  这句话,也就没有了后面的黑色背景,但是,也是没了窗体的关闭等等按钮了。。。。

 

 


 

 

 

posted on 2010-04-05 23:56  颜昌钢  阅读(1384)  评论(2编辑  收藏  举报