首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

wpf图片动画的有关问题

2013-09-05 
wpf图片动画的问题打个比方就如同QQ的最小化按钮那样鼠标移动上去和移出的效果这应该是两张图举例来说正常

wpf图片动画的问题
打个比方就如同QQ的最小化按钮那样  鼠标移动上去和移出的效果
这应该是两张图  举例来说正常是A图  鼠标移动上去B图渐入  鼠标移出B图渐出
这个图片的渐入渐出怎么实现呢?

我现在的代码上面的关闭按钮的样式
 <!--关闭按钮样式-->
    <Style x:Key="closeBtnStyle" TargetType="Button">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">

                    <Image Name="closeBtn" Source="/images/sysbtn_close_normal.png"  Height="29" />
                    
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Source" Value="/images/sysbtn_close_hover.png" TargetName="closeBtn" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="Source" Value="/images/sysbtn_close_down.png" TargetName="closeBtn" />

                        </Trigger>
                     
                        
                    </ControlTemplate.Triggers>
                </ControlTemplate>


            </Setter.Value>
        </Setter>
    </Style>


这样只能让图片一下就显示出来  而不能想QQ那样渐渐的出来  是不是需要用动画?动画颜色我会  但是这个图片怎么弄呢  我还是wpf入门阶段 这个还请各位大大帮一下哈 wpf?动画 移动 鼠标 图片
[解决办法]


<Style x:Key="closeBtnStyle" TargetType="Button">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Grid>
                    <Image Name="btnImg" Source="/images/sysbtn_close_normal.png" Height="29" />
                    <Image Name="hoverImg" Source="/images/sysbtn_close_hover.png" Height="29" Opacity="0" />
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter TargetName="btnImg" Property="Source" Value="/images/sysbtn_close_down.png" />
                        <Setter TargetName="hoverImg" Property="Visibility" Value="Hidden" />
                    </Trigger>


                    <Trigger Property="IsMouseOver" Value="True">
                        <Trigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="hoverImg" Storyboard.TargetProperty="Opacity"
                                                        To="1" Duration="0:0:.5" />
                                </Storyboard>
                            </BeginStoryboard>
                        </Trigger.EnterActions>
                        <Trigger.ExitActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="hoverImg" Storyboard.TargetProperty="Opacity"
                                                        To="0" Duration="0:0:0.2" />


                                </Storyboard>
                            </BeginStoryboard>
                        </Trigger.ExitActions>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


[解决办法]
    <Window.Resources>
        <Storyboard x:Key="loginStoryboard">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid">
                <SplineDoubleKeyFrame KeyTime="0" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <PointAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)" Storyboard.TargetName="grid">
                <SplinePointKeyFrame KeyTime="0" Value="0.5,0.5"/>
                <SplinePointKeyFrame KeyTime="0:0:1" Value="0.5,0.5"/>
            </PointAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" 
                                           Storyboard.TargetName="grid">


                <SplineDoubleKeyFrame KeyTime="0" Value="-1"/>
                <SplineDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </Window.Resources>
    <Button   Grid.Column="1" Grid.ColumnSpan="2" Height="28"   Width="95"  HorizontalAlignment="Left"  Template="{DynamicResource dlButtonTemplate}"  IsDefault="True"   Name="btnLogin" Click="btnLogin_Click">

                        </Button>
                        <Button   Grid.Column="3" Grid.ColumnSpan="2" Height="28"   Width="95"  HorizontalAlignment="Left"  Template="{DynamicResource qxButtonTemplate}" IsCancel="True"   Name="btnCancel" Click="btnCancel_Click">

                        </Button>
                    </Grid>

热点排行