DCSIMG
<howto> Start Animation on Model property changed </howto> - Essential WPF

<howto> Start Animation on Model property changed </howto>

Lately I’m teaching UI designers to work with WPF, and one of my students asked me how to start an animation when model’s property changes, and this was my answer:

If the animated element is part of a DataTemplate, use DataTrigger to monitor data changes and to start the animation. But if you don’t have a DataTemplate or the animated element is not part of the DataTemplate, create a Style for that element, and use a simple DataTrigger within.

<Style x:Key="PathStyle" TargetType="{x:Type Path}">
    <Style.Resources>
        <Storyboard x:Key="DataChangeAnimation">
            ...
        </Storyboard>
    </Style.Resources>
    <Style.Triggers>
        <DataTrigger Binding="{Binding Path=IsDirty}" Value="True">
            <DataTrigger.EnterActions>
                <BeginStoryboard x:Name="DataChangeAnimation_BeginStoryboard"
                                 Storyboard="{StaticResource DataChangeAnimation}"/>
            </DataTrigger.EnterActions>
        </DataTrigger>
    </Style.Triggers>
</Style>

Be aware that if you use a style, you can not specify the TargetName, hence you should create a Style for the animated element and place both the animation and data DataTrigger inside.

Feel free to download the source from here.

Published Friday, November 06, 2009 10:51 AM by Tomer Shamam

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above:
Powered by Community Server (Commercial Edition), by Telligent Systems