views:

304

answers:

1

Can anyone tell me how this would look like in C#?

<EventTrigger RoutedEvent="Button.Click" SourceName="btnSplit">
                <EventTrigger.Actions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation From="0" To="1" Duration="0:0:0.25" Storyboard.TargetName="gridSplit" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"/>
                            <DoubleAnimation From="1" To="0" Duration="0:0:0.25" Storyboard.TargetName="gridJoin" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger.Actions>
            </EventTrigger>

I don't need the "RoutedEvent"-Part because I want to execute the Code when the User Clicks on a Button programmatically (Click-EventHandler).. The RoutedEvent Handler gets called first which is why I can't do a if-else and need to do the whole Animation in code-behind.

Thanks in advance!

MemphiZ

+2  A: 

Solved it!

Just give the Storyboard an x:Name and then call it like this:

<Storyboard x:Name="storyBoardName">
    <DoubleAnimation From="0" To="1" Duration="0:0:0.25" Storyboard.TargetName="grid1" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"/>
    <DoubleAnimation From="1" To="0" Duration="0:0:0.25" Storyboard.TargetName="grid2" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"/>
</Storyboard>

Storyboard story = (Storyboard)this.FindResource("storyBoardName");  
this.BeginStoryboard(story);
MemphiZ