I would like to have a trigger on an image that extends AND and truncates ItemSource, animating its height property.
I have a generic ItemSource associated with an ObservableCollection, so I don't know the overall height of this control.
After clicking the image, it should change its glyph of the image source to show that the items source is expanded. After clicking again, the ItemsSource element should begin to shrink from the current height to 0 - because the first animation may not end.
I currently have the following image trigger:
<Image Name="ExpandImage" Source="ArrowDown.png"> <Image.Triggers> <EventTrigger RoutedEvent="Image.MouseLeftButtonDown"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetProperty="Height" Storyboard.TargetName="myItemsControl" From="0" To="300" Duration="0:0:2" /> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> </Image.Triggers> </Image>
This is ugly because it animates to a fixed height - I need it to be close to the total (unknown height) of the ItemsControl element. In addition, it supports only one-way (expanding) animation.
My ItemsControl is simple:
<ItemsControl Name="myItemsControl" ItemsSource="{Binding Items}" Height="0" > <ItemsControl.ItemTemplate> <DataTemplate> <c:CustomUserControl/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>
source share