Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.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
C# 动画按钮图像_C#_Wpf_Silverlight_Wpf Animation - Fatal编程技术网

C# 动画按钮图像

C# 动画按钮图像,c#,wpf,silverlight,wpf-animation,C#,Wpf,Silverlight,Wpf Animation,我有一个按钮,我在上面添加2个图像。稍后,我必须在这些按钮的图像上添加动画。 在下面的Xaml代码中,我使用的是按钮模板,但在应用了模板之后,按钮的原始行为丢失了,比如没有边框,鼠标悬停时光标没有变化等等。它就像平面图一样 如何恢复按钮的默认行为 <Button Height="89" Margin="0,62,158,0" Name="buttonStart" VerticalAlignment="Top" Click="buttonStart_Click" Horizo

我有一个按钮,我在上面添加2个图像。稍后,我必须在这些按钮的图像上添加动画。 在下面的Xaml代码中,我使用的是按钮模板,但在应用了模板之后,按钮的原始行为丢失了,比如没有边框,鼠标悬停时光标没有变化等等。它就像平面图一样

如何恢复按钮的默认行为

        <Button Height="89" Margin="0,62,158,0" Name="buttonStart" VerticalAlignment="Top" Click="buttonStart_Click" HorizontalAlignment="Right" Width="133" >
        <Button.Template>
            <ControlTemplate TargetType="Button" >
                <Grid>
                    <Image x:Name="Normal" Source="/TFSCheckinReportGenerator;component/Resource/generate.png" Height="80" Width="80" Opacity="1"></Image>
                    <Image x:Name="Waiting" Source="/TFSCheckinReportGenerator;component/Resource/waiting.png" Height="80" Width="80" Opacity="0"></Image>
                </Grid>
                <ControlTemplate.Resources>

                    <Storyboard x:Key="ChangeImageToWaiting">
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Normal" Storyboard.TargetProperty="Opacity">
                            <SplineDoubleKeyFrame Value="0"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Waiting" Storyboard.TargetProperty="Opacity">
                            <SplineDoubleKeyFrame Value="1"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>

                    <Storyboard x:Key="Progress" RepeatBehavior="Forever">
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Waiting" Storyboard.TargetProperty="Width" Duration="00:00:01" AutoReverse="True">
                            <SplineDoubleKeyFrame Value="40"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Waiting" Storyboard.TargetProperty="Height" Duration="00:00:01" AutoReverse="True">
                            <SplineDoubleKeyFrame Value="40"/>
                        </DoubleAnimationUsingKeyFrames>

                    </Storyboard>
                </ControlTemplate.Resources>
            </ControlTemplate>
        </Button.Template>
    </Button>

使用ContentTemplateDataTemplate代替模板和控制模板,它将有助于显示按钮的原始行为,如边框和鼠标悬停时更改按钮外观等

定义控件的外观。指定如何显示包含在/显示在中的内容

 <Button Height="89" Margin="0,62,158,0" Name="buttonStart" VerticalAlignment="Top" HorizontalAlignment="Right" Width="133" >
        <Button.ContentTemplate>
            <DataTemplate>
                <Grid>
                    <Image x:Name="Normal" Source="catalogscreen.png" Height="80" Width="80" Opacity="1"></Image>
                    <Image x:Name="Waiting" Source="catalogscreen.png" Height="80" Width="80" Opacity="0"></Image>
                </Grid>
                <DataTemplate.Resources>
                    <Storyboard x:Key="ChangeImageToWaiting">
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Normal" Storyboard.TargetProperty="Opacity">
                            <SplineDoubleKeyFrame Value="0"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Waiting" Storyboard.TargetProperty="Opacity">
                            <SplineDoubleKeyFrame Value="1"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                    <Storyboard x:Key="Progress" RepeatBehavior="Forever">
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Waiting" Storyboard.TargetProperty="Width" Duration="00:00:01" AutoReverse="True">
                            <SplineDoubleKeyFrame Value="40"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Waiting" Storyboard.TargetProperty="Height" Duration="00:00:01" AutoReverse="True">
                            <SplineDoubleKeyFrame Value="40"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </DataTemplate.Resources>
            </DataTemplate>
        </Button.ContentTemplate>
    </Button>

改为应用于样式模板并继承其余部分。