事件触发器不起作用

时间:2010-08-18 10:46:48

标签: .net silverlight events triggers windows-phone-7

我的Windows Phone 7 Silverlight应用程序中有一些触发器,例如

<Grid x:Name="ContentGrid" Grid.Row="1" Background="Red" Height="100">
    <Grid.Triggers>
        <EventTrigger RoutedEvent="Loaded">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="Opacity">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                        <SplineDoubleKeyFrame KeyTime="00:00:10" Value="1"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Grid.Triggers>
</Grid>

但是当Loaded事件触发时,会发生XamlParseException。 我用谷歌搜索了一下,但一无所获。

有什么想法找到解决方案吗? 感谢。

1 个答案:

答案 0 :(得分:5)

我改变了你的代码:

  • 将RoutedEvent更改为Grid.Loaded
  • 添加了TargetName以及对Grid的引用
  • 将TargetProperty更改为Grid.Opacity

查看以下代码:

<Grid x:Name="ContentGrid" Grid.Row="1" Background="Red" Height="100">
        <Grid.Triggers>
            <EventTrigger RoutedEvent="Grid.Loaded">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00"  Storyboard.TargetName="ContentGrid" Storyboard.TargetProperty="Grid.Opacity">
                            <SplineDoubleKeyFrame KeyTim>
                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                            <SplineDoubleKeyFrame KeyTime="00:00:10" Value="1"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Grid.Triggers>
</Grid>