为什么WPF中的加载故事板事件不会触发?

时间:2009-09-06 17:18:00

标签: .net wpf xaml

好的,出于某种原因我在WPF中为window.loaded设置了一个事件触发器以触发AnimationBoard故事板,但由于某种原因它不想加载。有什么想法吗?谢谢!以下是代码:


<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Class="CFPSite.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="800" Height="600" Background="Black" mc:Ignorable="d">

<Window.Resources>

    <Storyboard x:Key="AnimationBoard">
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="textBlock" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="6.667"/>
            <SplineDoubleKeyFrame KeyTime="00:00:00.5250000" Value="71.333"/>
            <SplineDoubleKeyFrame KeyTime="00:00:01.8000000" Value="-176.167"/>
            <SplineDoubleKeyFrame KeyTime="00:00:02.8000000" Value="11.333"/>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="textBlock" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="-4.666"/>
            <SplineDoubleKeyFrame KeyTime="00:00:00.5250000" Value="-130.666"/>
            <SplineDoubleKeyFrame KeyTime="00:00:01.8000000" Value="-114.166"/>
            <SplineDoubleKeyFrame KeyTime="00:00:02.8000000" Value="23.834"/>
        </DoubleAnimationUsingKeyFrames>
        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="AboutUs" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
            <SplineColorKeyFrame KeyTime="00:00:02.8000000" Value="White"/>
        </ColorAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="AboutUs" Storyboard.TargetProperty="(TextElement.FontSize)">
            <SplineDoubleKeyFrame KeyTime="00:00:02.8000000" Value="29.333"/>
        </DoubleAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="AboutUs" Storyboard.TargetProperty="(TextElement.FontFamily)">
            <DiscreteObjectKeyFrame KeyTime="00:00:02.8000000">
                <DiscreteObjectKeyFrame.Value>
                    <FontFamily>Fonts/#Calibri</FontFamily>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
        </ObjectAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="AboutUs" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
            <SplineDoubleKeyFrame KeyTime="00:00:02.8000000" Value="-1.5"/>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="AboutUs" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
            <SplineDoubleKeyFrame KeyTime="00:00:02.8000000" Value="1.5"/>
        </DoubleAnimationUsingKeyFrames>
        <PointAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Services" Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)">
            <SplinePointKeyFrame KeyTime="00:00:02.8000000" Value="0.484,2.565"/>
        </PointAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Services" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
            <SplineDoubleKeyFrame KeyTime="00:00:02.8000000" Value="70.5"/>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Services" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
            <SplineDoubleKeyFrame KeyTime="00:00:02.8000000" Value="-3"/>
        </DoubleAnimationUsingKeyFrames>
        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Services" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
            <SplineColorKeyFrame KeyTime="00:00:02.8000000" Value="White"/>
        </ColorAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Services" Storyboard.TargetProperty="(TextElement.FontSize)">
            <SplineDoubleKeyFrame KeyTime="00:00:02.8000000" Value="29.333"/>
        </DoubleAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Services" Storyboard.TargetProperty="(TextElement.FontFamily)">
            <DiscreteObjectKeyFrame KeyTime="00:00:02.8000000">
                <DiscreteObjectKeyFrame.Value>
                    <FontFamily>Fonts/#Calibri</FontFamily>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
        </ObjectAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ContactUs" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
            <SplineDoubleKeyFrame KeyTime="00:00:02.8000000" Value="144"/>
        </DoubleAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ContactUs" Storyboard.TargetProperty="(TextElement.FontFamily)">
            <DiscreteObjectKeyFrame KeyTime="00:00:02.8000000">
                <DiscreteObjectKeyFrame.Value>
                    <FontFamily>Fonts/#Calibri</FontFamily>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
        </ObjectAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ContactUs" Storyboard.TargetProperty="(TextElement.FontSize)">
            <SplineDoubleKeyFrame KeyTime="00:00:02.8000000" Value="29.333"/>
        </DoubleAnimationUsingKeyFrames>
        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ContactUs" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
            <SplineColorKeyFrame KeyTime="00:00:02.8000000" Value="White"/>
        </ColorAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="FAQ" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
            <SplineDoubleKeyFrame KeyTime="00:00:02.8000000" Value="225"/>
        </DoubleAnimationUsingKeyFrames>
        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="FAQ" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
            <SplineColorKeyFrame KeyTime="00:00:02.8000000" Value="White"/>
        </ColorAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="FAQ" Storyboard.TargetProperty="(TextElement.FontFamily)">
            <DiscreteObjectKeyFrame KeyTime="00:00:02.8000000">
                <DiscreteObjectKeyFrame.Value>
                    <FontFamily>Fonts/#Calibri</FontFamily>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
        </ObjectAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="FAQ" Storyboard.TargetProperty="(TextElement.FontSize)">
            <SplineDoubleKeyFrame KeyTime="00:00:02.8000000" Value="29.333"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
    <Storyboard x:Key="EnlargeText">
        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="AboutUs" Storyboard.TargetProperty="(TextElement.FontFamily)">
            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                <DiscreteObjectKeyFrame.Value>
                    <FontFamily>Fonts/#Calibri</FontFamily>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
            <DiscreteObjectKeyFrame KeyTime="00:00:00.5000000">
                <DiscreteObjectKeyFrame.Value>
                    <FontFamily>Fonts/#Calibri</FontFamily>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
        </ObjectAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="AboutUs" Storyboard.TargetProperty="(TextElement.FontSize)">
            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="32"/>
            <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="37.333"/>
        </DoubleAnimationUsingKeyFrames>
        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="AboutUs" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
            <SplineColorKeyFrame KeyTime="00:00:00" Value="White"/>
            <SplineColorKeyFrame KeyTime="00:00:00.5000000" Value="White"/>
        </ColorAnimationUsingKeyFrames>
    </Storyboard>
    <Storyboard x:Key="ShrinkText">

    <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="AboutUs" Storyboard.TargetProperty="(TextElement.FontFamily)">
            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                <DiscreteObjectKeyFrame.Value>
                    <FontFamily>Fonts/#Calibri</FontFamily>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
            <DiscreteObjectKeyFrame KeyTime="00:00:00.5000000">
                <DiscreteObjectKeyFrame.Value>
                    <FontFamily>Fonts/#Calibri</FontFamily>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
        </ObjectAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="AboutUs" Storyboard.TargetProperty="(TextElement.FontSize)">
            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="37.33"/>
            <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="32"/>
        </DoubleAnimationUsingKeyFrames>
        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="AboutUs" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
            <SplineColorKeyFrame KeyTime="00:00:00" Value="White"/>
            <SplineColorKeyFrame KeyTime="00:00:00.5000000" Value="White"/>
        </ColorAnimationUsingKeyFrames>


    </Storyboard>
    <Storyboard x:Key="ServicesEnlargeText">

    <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Services" Storyboard.TargetProperty="(TextElement.FontFamily)">
            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                <DiscreteObjectKeyFrame.Value>
                    <FontFamily>Fonts/#Calibri</FontFamily>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
            <DiscreteObjectKeyFrame KeyTime="00:00:00.5000000">
                <DiscreteObjectKeyFrame.Value>
                    <FontFamily>Fonts/#Calibri</FontFamily>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
        </ObjectAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Services" Storyboard.TargetProperty="(TextElement.FontSize)">
            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="32"/>
            <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="37.333"/>
        </DoubleAnimationUsingKeyFrames>
        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Services" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">

            <SplineColorKeyFrame KeyTime="00:00:00" Value="White"/>
            <SplineColorKeyFrame KeyTime="00:00:00.5000000" Value="White"/>
        </ColorAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
            <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="-9.5"/>
        </DoubleAnimationUsingKeyFrames>



    </Storyboard>
    <Storyboard x:Key="ServicesShrinkText">
        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Services" Storyboard.TargetProperty="(TextElement.FontFamily)">
            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                <DiscreteObjectKeyFrame.Value>
                    <FontFamily>Fonts/#Calibri</FontFamily>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
            <DiscreteObjectKeyFrame KeyTime="00:00:00.5000000">
                <DiscreteObjectKeyFrame.Value>
                    <FontFamily>Fonts/#Calibri</FontFamily>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
        </ObjectAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Services" Storyboard.TargetProperty="(TextElement.FontSize)">
            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="37.33"/>
            <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="32"/>
        </DoubleAnimationUsingKeyFrames>
        <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Services" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
            <SplineColorKeyFrame KeyTime="00:00:00" Value="White"/>
            <SplineColorKeyFrame KeyTime="00:00:00.5000000" Value="White"/>
        </ColorAnimationUsingKeyFrames>

    </Storyboard>
</Window.Resources>


    <Grid x:Name="LayoutRoot" Width="800" Height="600" RenderTransformOrigin="0.5,0.5" Margin="-8,-20,-8,-16" Loaded="Window_Loaded">
    <Grid.RenderTransform>
        <TransformGroup>
            <ScaleTransform/>
            <SkewTransform/>
            <RotateTransform/>
            <TranslateTransform/>
        </TransformGroup>
    </Grid.RenderTransform>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Image Margin="200,3.493,165.14,29.507" Source="dollarladder.jpg" Stretch="Fill" d:IsLocked="True"/>
    <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="27,58,0,0" VerticalAlignment="Top" Width="253.167" Height="193.96" RenderTransformOrigin="0.5,0.5" FontFamily="Fonts/#Calibri" FontSize="16" Foreground="White" Text="Financial Planning, it's not merely a way of getting rich. It's a delicate balance of building trust in the clients, working your way up gradually through various ladders of wealth and property.  Occasionally one may stumble but the end result will ultimately be with enough perseverance, one will reach the top." TextWrapping="Wrap">
        <TextBlock.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform Angle="1.381"/>
                <TranslateTransform/>
            </TransformGroup>
        </TextBlock.RenderTransform>
    </TextBlock>
    <TextBlock x:Name="AboutUs" HorizontalAlignment="Right" Margin="0,46,67,0" VerticalAlignment="Top" Width="160" Height="46" Text="About Us" TextWrapping="Wrap" RenderTransformOrigin="0.5,0.5" d:IsLocked="True">
        <TextBlock.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform/>
                <TranslateTransform/>
            </TransformGroup>
        </TextBlock.RenderTransform>
    </TextBlock>
    <TextBlock x:Name="Services" HorizontalAlignment="Right" Margin="0,46,67,0" VerticalAlignment="Top" Width="160" Height="46" RenderTransformOrigin="0.5,0.5" TextWrapping="Wrap" d:IsLocked="True"><TextBlock.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform/>
                <TranslateTransform/>
            </TransformGroup>
        </TextBlock.RenderTransform><Run Text="Services"/><LineBreak/><Run Text=""/></TextBlock>
    <TextBlock x:Name="ContactUs" HorizontalAlignment="Right" Margin="0,46,67,0" VerticalAlignment="Top" Width="160" Height="46" RenderTransformOrigin="0.5,0.5" TextWrapping="Wrap"><TextBlock.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform/>
                <TranslateTransform/>
            </TransformGroup>
        </TextBlock.RenderTransform><Run Text="Contact Us"/><LineBreak/><Run Text=""/></TextBlock>
    <TextBlock x:Name="FAQ" HorizontalAlignment="Right" Margin="0,46,67,0" VerticalAlignment="Top" Width="160" Height="46" RenderTransformOrigin="0.5,0.5" TextWrapping="Wrap" Text="FAQ" d:IsLocked="True"><TextBlock.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform/>
                <TranslateTransform/>
            </TransformGroup>
        </TextBlock.RenderTransform></TextBlock>
</Grid>
<Window.Triggers>

        <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="AboutUs">
        <BeginStoryboard x:Name="EnlargeText_BeginStoryboard" Storyboard="{StaticResource ShrinkText}"/>
    </EventTrigger>
    <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="AboutUs">
        <BeginStoryboard x:Name="EnlargeText_BeginStoryboard1" Storyboard="{StaticResource EnlargeText}"/>
    </EventTrigger>
    <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="Services">
        <BeginStoryboard x:Name="ShrinkText_BeginStoryboard" Storyboard="{StaticResource ServicesEnlargeText}"/>
    </EventTrigger>
    <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="Services">
        <BeginStoryboard x:Name="ServicesShrinkText_BeginStoryboard" Storyboard="{StaticResource ServicesShrinkText}"/>
    </EventTrigger>
    <EventTrigger RoutedEvent="FrameworkElement.Loaded">
        <BeginStoryboard Storyboard="{StaticResource AnimationBoard}"/>
    </EventTrigger>

</Window.Triggers>

1 个答案:

答案 0 :(得分:0)

没关系,不得不重建动画,但不确定是什么造成了这种情况。