tags:

views:

41

answers:

1

Hi guys,

I am trying to animate the main window, changing the width and the height. I use a DataTrigger in the main window style to change it but when I run it first triggers the width change and then the height change, I want both of them changing at the same time.

<Storyboard x:Key="TransitToExecution">
    <!-- This animation hides the main panel -->
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Duration="0:0:0.5">
        <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="{StaticResource ScreenHeight}"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Duration="0:0:0.5">
        <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="{StaticResource ScreenWidth}"/>
    </DoubleAnimationUsingKeyFrames>
</Storyboard>

The data trigger is very simple:

    <Window.Style>
    <Style>
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsWideScreen}" Value="true" >
                <DataTrigger.EnterActions>
                    <BeginStoryboard Storyboard="{StaticResource TransitToExecution}"/>
                </DataTrigger.EnterActions>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Window.Style>

Any ideas why these two animations do not run simultaneuosly?

Thanks

A: 

I believe that you need to have two BeginStoryboards in your trigger - one for the width, one for the height.

<Storyboard x:Key="TransitToExecutionHeight">
    <!-- This animation hides the main panel -->
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Duration="0:0:0.5">
        <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="{StaticResource ScreenHeight}"/>
    </DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="TransitToExecutionWidth">
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Duration="0:0:0.5">
        <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="{StaticResource ScreenWidth}"/>
    </DoubleAnimationUsingKeyFrames>
</Storyboard>

And then in your Trigger:

    <Window.Style>
    <Style>
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsWideScreen}" Value="true" >
                <DataTrigger.EnterActions>
                    <BeginStoryboard Storyboard="{StaticResource TransitToExecutionWidth}"/>
                    <BeginStoryboard Storyboard="{StaticResource TransitToExecutionHeight}"/>
                </DataTrigger.EnterActions>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Window.Style>
Wonko the Sane
No, actually does not work either. It seems that it can move the window height and width at the same time.
No hay Problema
I'm not sure I understand your comment. Do you mean it *cannot* move the height and width at the same time? If this is true, it may be either a .NET 4.0 or an EasingDoubleKeyFrame issue - I will defer to other experts on this, as I don't have that available in front of me at the moment. All I can say (for the moment, anyway) is that I can get width and height to change at the same time using a LinearDoubleKeyFrame in .NET 3.5.
Wonko the Sane