Animation Problem!

Hello:

When reading the Hands-On Lab, I enjoy myself.

There is a class named " Photo" to store the path of Image

A collection:

public class PhotoList : ObservableCollection<Photo>

A ListBox whose ItemsSource is binded to the PhotoList;

But I met a strange problem ,

The following code works very well when the PhotoList is steady.

<EventTrigger RoutedEvent="GotFocus">
<EventTrigger.Actions>
<BeginStoryboard>
<BeginStoryboard.Storyboard>
<Storyboard>
<DoubleAnimation
Duration="0:0:0.2"
Storyboard.TargetProperty="MaxHeight"
To="90" />
</Storyboard>
</BeginStoryboard.Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>

But When I add some codes to change PhotoList

private void OnSelectChanged(object sender, RoutedEventArgs e)
{
if (Photos == null)
return;
int selectedIndex=PhotosListBox.SelectedIndex;

if ( selectedIndex< 2)
{

Photos.RemoveAt(4);
Photos.Insert(0, new Photo("../rs/Winter1.jpg"));

}
else if (selectedIndex > 2)
{
Photos.RemoveAt(0);
Photos.Insert(4, new Photo("../rs/Leaf1.jpg"));
}
}

It doesn't work now:

System.InvalidOperationException: System.Windows.Media.Animation.DoubleAnimation: cannot use default destination value of .

I don't know the reason,and the method either.

Is there anybody who can help me

Thank U!



Answer this question

Animation Problem!

  • fark

    Becuse when you don't specify a value, the default value used by WPF is Nan (Not a Number)

    And when you try to reach this value, you get an exception

    HTH



  • muhsin ugur

    Thank U for your method.

    But I do want to know why this method works and why my way doesn't.


  • TCDooM

    Try to specify the From Property of your DoubleAnimation

  • Animation Problem!