Harry Bloom
Harry Bloom

Reputation: 2449

Cannot animate grid from previous value to a new value

I am trying to animate the grid height property from two variables, the previous height and the new height. The problem I am facing is that I repeatedly load a new set of values and in turn reload the data binding. When the XAML binding gets loaded, all previous values are lost and we just have the new variable.

I realise I can just store the value in the model however I want to do this just in XAML code and have no dependency on the old values.

This is what I have so far:

<Grid x:Name="MeasureGrid"  Background="{Binding bindingBackgroundColor}" MinHeight="30" MaxHeight="200" VerticalAlignment="Bottom"  Loaded="startAnimaton" >
<Grid.Resources>
    <Storyboard x:Name="myStoryboard" Completed="completed">
        <DoubleAnimation
            Storyboard.TargetName="MeasureGrid"
            Storyboard.TargetProperty="Height"
            EnableDependentAnimation="True"
            From="30"
            To="{Binding bindingNewHeight}" 
            Duration="0:0:1" />
    </Storyboard>
</Grid.Resources>

As you can see, it is the "From" property that is the issue. Can anyone point out a way to tackle this?

Upvotes: 2

Views: 49

Answers (2)

Corcus
Corcus

Reputation: 1090

Have you tried using the FillBehavior of the Storyboard and removing the From attribute?

<Storyboard x:Name="myStoryboard" Completed="completed">
    <DoubleAnimation
        Storyboard.TargetName="MeasureGrid"
        Storyboard.TargetProperty="Height"
        EnableDependentAnimation="True"            
        To="{Binding bindingNewHeight}"
        FillBehavior="HoldEnd"
        Duration="0:0:1" />
</Storyboard>

This is what I would try.

Upvotes: 0

grabthefish
grabthefish

Reputation: 918

you can always try to bind the from value to the height of the measuregrid like so:

 From="{Binding ElementName=MeasureGrid, Path=Height}"

Else you could remove the From and To attributes and use the By attribute

Upvotes: 1

Related Questions