Vitali Fokin
Vitali Fokin

Reputation: 203

Event triggers don't work

I have some trigger in my Windows Phone 7 Silverlight app such as

<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>

But when Loaded event fires, XamlParseException occurs. I googled a bit, but found nothing.

Any idea to find solution? Thanks.

Upvotes: 1

Views: 1297

Answers (1)

Wouter Janssens
Wouter Janssens

Reputation: 1613

I changed your code a bit:

  • Changed the RoutedEvent to Grid.Loaded
  • Added the TargetName with a reference to the Grid
  • Change the TargetProperty to Grid.Opacity

view the code below:

<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>

Upvotes: 5

Related Questions