Question

I have a button inside a DataTemplate of a ListBox.

Whenever a button is added to the Listbox,I want to animate the appearance of the new button by setting the opacity from minimum to maximum.

How do I do this?

Was it helpful?

Solution

You could listen to Loaded event. When Loaded wpf will trigger your animation.

Here is an example how you could achieve that:

<Button Height="23" Margin="102,95,100,0" Name="button3" VerticalAlignment="Top" Content="Opacity">
            <Button.Triggers>
                <EventTrigger RoutedEvent="Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                                             Storyboard.TargetProperty="Opacity"
                                             From="1"
                                             To="0"
                                             Duration="0:0:1"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>    
        </Button>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top