Question

I have a DataTemplate which is used to populate a longlistselector. In this DataTemplate are 2 rows. Row 1 contains a button, when pressed it should slide open row 2. The problem is when I run the app I get an UnhandledException.

Here is the DataTemplate:

<DataTemplate>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>     

        <!-- 1st ROW -->
        <Border Background="Red" HorizontalAlignment="Stretch">                            
            <Grid>                                
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>                            
                <TextBlock Text="Test Item" FontSize="42" />
                <Button Content="v" Grid.Column="1">
                    <Button.Triggers>                                        
                        <EventTrigger RoutedEvent="Button.Tap">                                            
                            <BeginStoryboard>                                                
                                <Storyboard x:Name="myBoard" TargetProperty="Border.Height" TargetName="Slider">
                                    <DoubleAnimation From="0" To="60" Duration="0:0:2" />
                                </Storyboard>                                                
                            </BeginStoryboard>                                            
                        </EventTrigger>
                    </Button.Triggers>
                </Button>
            </Grid>
        </Border>

        <!-- 2nd ROW -->
        <Border x:Name="Slider" Grid.Row="1" Background="Green" HorizontalAlignment="Stretch" Height="0">
            <TextBlock Text="Slider" FontSize="42" />
        </Border>

    </Grid>    
</DataTemplate>

/edit:

When I use the trigger on the Grid's Loaded event it does work. It seems Silverlight only supports the Loaded event for the RoutedEvent property. As described here:

http://msdn.microsoft.com/en-us/library/system.windows.eventtrigger.routedevent(v=vs.95).aspx

Although using the Loaded event of the button doesn't work either.

Was it helpful?

Solution

I found a solution:

<Button Content="v" Grid.Column="1">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Tap">
            <eim:ControlStoryboardAction ControlStoryboardOption="Play">
                <eim:ControlStoryboardAction.Storyboard>
                    <Storyboard TargetProperty="(Border.Height)" TargetName="Slider">
                        <DoubleAnimation From="0" To="60" Duration="0:0:2" />
                    </Storyboard>
                </eim:ControlStoryboardAction.Storyboard>
            </eim:ControlStoryboardAction>
        </i:EventTrigger>
    </i:Interaction.Triggers>                                    
</Button>

Apparently you can define the storyboard inside the ControlStoryboardAction, which was exactly what I needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top