Given the following custom animation class : (From one of the answers to this question) :
public class BrushAnimation : AnimationTimeline {
public Brush From {
get { return this.GetValue( FromProperty ) as Brush; }
set { this.SetValue( FromProperty, value ); }
}
public Brush To {
get { return this.GetValue( ToProperty ) as Brush; }
set { this.SetValue( ToProperty, value ); }
}
public static readonly DependencyProperty
FromProperty = DependencyProperty.Register(
"From", typeof( Brush ), typeof( BrushAnimation ) ),
ToProperty = DependencyProperty.Register(
"To", typeof( Brush ), typeof( BrushAnimation ) );
public override Type TargetPropertyType {
get { return typeof( Brush ); }
}
public override object GetCurrentValue(
object defaultOriginValue,
object defaultDestinationValue,
AnimationClock animationClock
) {
return this.GCV(
defaultOriginValue as Brush,
defaultDestinationValue as Brush,
animationClock );
}
protected override Freezable CreateInstanceCore( ) {
return new BrushAnimation( );
}
public object GCV(
Brush defaultOriginValue,
Brush defaultDestinationValue,
AnimationClock animationClock
) {
if ( !animationClock.CurrentProgress.HasValue )
return Brushes.Transparent;
defaultOriginValue = this.From ?? defaultOriginValue;
defaultDestinationValue = this.To ?? defaultDestinationValue;
return animationClock.CurrentProgress.Value == 0 ? defaultOriginValue
: animationClock.CurrentProgress.Value == 1 ? defaultDestinationValue
: new VisualBrush( new Border( ) {
Width = 1,
Height = 1,
Background = defaultOriginValue,
Child = new Border( ) {
Background = defaultDestinationValue,
Opacity = animationClock.CurrentProgress.Value
}
} );
}
}
Given the following use case :
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:Components="clr-namespace:FooBar.Components"
xmlns:Animations="clr-namespace:FooBar.Classes">
<Style TargetType="{x:Type Components:MyButtons}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<!--Stuff-->
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="GotFocus">
<BeginStoryboard>
<Storyboard>
<Animations:BrushAnimation
Storyboard.TargetName="Foo"
Storyboard.TargetProperty="BarBrush"
Duration="0:0:0.3"
From="<What Do I Put Here?>"
To="<What Do I Put HERE?!>"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Based on what I've read, you can't bind a Timelines From and To values because Freezable
.
I read a possible workaround but it uses a Tag property and I think this use case may go beyond the scope of that proposed solution.
Is there any way for me to have the Timeline read the values from my component?