Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 动画图像按钮_Wpf_Xaml_Animation_Imagebutton - Fatal编程技术网

Wpf 动画图像按钮

Wpf 动画图像按钮,wpf,xaml,animation,imagebutton,Wpf,Xaml,Animation,Imagebutton,我需要一个自定义图像按钮,我已经使用了一段时间的帮助。它工作得很好,但我不知道如何在正常、鼠标悬停、按下这三种状态下设置按钮的动画: 正常到鼠标悬停 鼠标悬停 我对XAML没有那么熟练,所以我想不出来。不管怎样,下面是我一直在使用的代码: <Button Height="40" HorizontalAlignment="Left" IsEnabled="True" IsHitTestVisible="True" Margin="262,219,0,0" Name="home_btn" Ve

我需要一个自定义图像按钮,我已经使用了一段时间的帮助。它工作得很好,但我不知道如何在正常、鼠标悬停、按下这三种状态下设置按钮的动画:

正常到鼠标悬停 鼠标悬停 我对XAML没有那么熟练,所以我想不出来。不管怎样,下面是我一直在使用的代码:

<Button Height="40" HorizontalAlignment="Left" IsEnabled="True" IsHitTestVisible="True" Margin="262,219,0,0" Name="home_btn" VerticalAlignment="Top" Width="89">
    <Button.Template>
        <ControlTemplate TargetType="{x:Type Button}">
            <Grid>
                <Image Name="Normal" Source="normal.png" />
                <Image Name="Hover" Source="hover.png" Visibility="Hidden" />
                <Image Name="Pressed" Source="pressed.png" Visibility="Hidden" />
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="ButtonBase.IsPressed" Value="True">
                    <Setter Property="UIElement.Visibility" TargetName="Normal" Value="Hidden" />
                    <Setter Property="UIElement.Visibility" TargetName="Pressed" Value="Visible" />
                </Trigger>
                <Trigger Property="UIElement.IsMouseOver" Value="True">
                    <Setter Property="UIElement.Visibility" TargetName="Normal" Value="Hidden" />
                    <Setter Property="UIElement.Visibility" TargetName="Hover" Value="Visible" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Button.Template>
</Button>

任何答复都将不胜感激

对于这类事情,您可能应该使用,有关用法示例,请参阅其文档

对于这类事情,您可能应该使用,有关用法示例,请参阅其文档

完成动画的另一种方法是使用触发器,就像与

以下是您发布的代码中集成的一些示例代码:

 <Button Height="40" HorizontalAlignment="Left" IsEnabled="True" IsHitTestVisible="True" Margin="262,219,0,0" Name="home_btn" VerticalAlignment="Top" Width="89">
<Button.Template>
    <ControlTemplate TargetType="{x:Type Button}">
        <Grid>
            <Image Name="Normal" Source="normal.png" />
            <Image Name="Hover" Source="hover.png" Opacity="0"/>
            <Image Name="Pressed" Source="pressed.png" Opacity="0" />
        </Grid>
        <ControlTemplate.Resources>
            <Storyboard x:Key="MouseDownTimeLine">
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Pressed" Storyboard.TargetProperty="Opacity">
                    <SplineDoubleKeyFrame KeyTime="00:00:00.05" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="MouseUpTimeLine">
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Pressed" Storyboard.TargetProperty="Opacity">
                    <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="MouseEnterTimeLine">
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Hover" Storyboard.TargetProperty="Opacity">
                    <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="MouseExitTimeLine">
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Hover" Storyboard.TargetProperty="Opacity">
                    <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
             </Storyboard>
        </ControlTemplate.Resources>
        <ControlTemplate.Triggers>
            <Trigger Property="ButtonBase.IsPressed" Value="True">
               <Trigger.EnterActions>
                   <BeginStoryboard Storyboard="{StaticResource MouseDownTimeLine}"/>
               </Trigger.EnterActions>
               <Trigger.ExitActions>
                   <BeginStoryboard Storyboard="{StaticResource MouseUpTimeLine}"/>
               </Trigger.ExitActions>
            </Trigger>
            <Trigger Property="UIElement.IsMouseOver" Value="True">
                <Trigger.EnterActions>
                    <BeginStoryboard Storyboard="{StaticResource MouseEnterTimeLine}"/>
                </Trigger.EnterActions>
                <Trigger.ExitActions>
                    <BeginStoryboard Storyboard="{StaticResource MouseExitTimeLine}"/>
                </Trigger.ExitActions>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
</Button.Template>

完成动画的另一种方法是使用触发器,就像与

以下是您发布的代码中集成的一些示例代码:

 <Button Height="40" HorizontalAlignment="Left" IsEnabled="True" IsHitTestVisible="True" Margin="262,219,0,0" Name="home_btn" VerticalAlignment="Top" Width="89">
<Button.Template>
    <ControlTemplate TargetType="{x:Type Button}">
        <Grid>
            <Image Name="Normal" Source="normal.png" />
            <Image Name="Hover" Source="hover.png" Opacity="0"/>
            <Image Name="Pressed" Source="pressed.png" Opacity="0" />
        </Grid>
        <ControlTemplate.Resources>
            <Storyboard x:Key="MouseDownTimeLine">
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Pressed" Storyboard.TargetProperty="Opacity">
                    <SplineDoubleKeyFrame KeyTime="00:00:00.05" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="MouseUpTimeLine">
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Pressed" Storyboard.TargetProperty="Opacity">
                    <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="MouseEnterTimeLine">
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Hover" Storyboard.TargetProperty="Opacity">
                    <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="MouseExitTimeLine">
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Hover" Storyboard.TargetProperty="Opacity">
                    <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
             </Storyboard>
        </ControlTemplate.Resources>
        <ControlTemplate.Triggers>
            <Trigger Property="ButtonBase.IsPressed" Value="True">
               <Trigger.EnterActions>
                   <BeginStoryboard Storyboard="{StaticResource MouseDownTimeLine}"/>
               </Trigger.EnterActions>
               <Trigger.ExitActions>
                   <BeginStoryboard Storyboard="{StaticResource MouseUpTimeLine}"/>
               </Trigger.ExitActions>
            </Trigger>
            <Trigger Property="UIElement.IsMouseOver" Value="True">
                <Trigger.EnterActions>
                    <BeginStoryboard Storyboard="{StaticResource MouseEnterTimeLine}"/>
                </Trigger.EnterActions>
                <Trigger.ExitActions>
                    <BeginStoryboard Storyboard="{StaticResource MouseExitTimeLine}"/>
                </Trigger.ExitActions>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
</Button.Template>