In a previous post Steve asks "is it possible to bind an animation using xaml?". The example below shows how, binding the duration of an animation to a value in a text box. The animation, which is triggered when the button is clicked, changes the button's background color from orange to brown. The duration of the animation is bound to the value entered in the text box using the same {Binding} markup extension used throughout WPF. Although in this example the animation is bound to another element it could be bound to other sources like data from a relational database or a value in an Xml file.
Xaml Code (WPF Beta 2/June CTP)
<Window x:Class="LearnWPF.BoundAnimation.Window1"
xmlns="
http://schemas.microsoft.com/winfx/2006/xaml/presentation
"
xmlns:x="
http://schemas.microsoft.com/winfx/2006/xaml
"
Title="LearnWPF.BoundAnimation" Height="200" Width="350"
>
<StackPanel Margin="2">
<Button Width="200" Height="50" Name="animateMe"
Content="Click The Button to See Animation">
<Button.Background>
<SolidColorBrush x:Name="buttonBrush" />
</Button.Background>
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard Storyboard.TargetName="buttonBrush"
Storyboard.TargetProperty="Color" >
<ColorAnimation To="#58290A" From="#feca00"
Duration="{Binding ElementName=durationText, Path=Text}" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Button.Triggers>
</Button>
<StackPanel Orientation="Horizontal" Margin="2">
<TextBlock VerticalAlignment="Center">Animation Time (hours:minutes:seconds)</TextBlock>
<TextBox Name="durationText" Text="0:0:1" />
</StackPanel>
</StackPanel>
</Window>