WPF Controls: How to Reference Resources in Animations?

I have written a control and successfully created a storyboard to cause an animation during triggered events. It changes the fill of an ellipse for a duration of time. Instead of writing a new RadialGradientBrush each time I need to change the fill, I provided two of them in the resources.

EDIT: I have an Ellipse that is the main component to the control and is what is affected by the animation. It's implementation is simple and looks like this:

<Ellipse Name="myEllipse" Style="{StaticResource DimStyle}" />

When I add it to the storyboard (instead of referencing the brush as a resource), my animation works as intended. When I reference the brush as a resource I get this exception:

"Cannot find resource named 'IlluminatedStyle'. Resource names are case sensitive."

Inside of the storyboard, this is where it is currently referenced:

    <Storyboard x:Key="Foo">
                <DiscreteObjectKeyFrame KeyTime="0:0:0.01" Value="{StaticResource IlluminatedStyle}" />
                <DiscreteObjectKeyFrame KeyTime="0:0:0.85" Value="{StaticResource DimStyle}" />

The styles are closely identical and only the GradientStop color properties differ so I'll provide only one style for an example.

The Style Referenced

    <Style x:Key="IlluminatedStyle" TargetType="Ellipse">
        <Setter Property="Fill">
                    <GradientStop Color="#FF215416" Offset="1"/>
                    <GradientStop Color="#FE38DA2E" Offset="0"/>
                    <GradientStop Color="#FE81FF79" Offset="0.688"/>

So how do I correctly reference a style such as this in my Storyboard?

Note: The Storyboard and Style are both contained within the same UserControl.Resources tag but broken out for this example.

EDIT I put the Style before the Storyboard in UserControl.Resources and now I get an exception stating:

  "This Freezable cannot be frozen.
   at System.Windows.Freezable.Freeze()
   at System.Windows.Freezable.GetCurrentValueAsFrozen()
   at System.Windows.Media.Animation.TimelineCollection.GetCurrentValueAsFrozenCore(Freezable source)
   at System.Windows.Freezable.CloneCoreCommon(Freezable sourceFreezable, Boolean useCurrentValue, Boolean cloneFrozenValues)
   at System.Windows.Media.Animation.Timeline.GetCurrentValueAsFrozenCore(Freezable sourceFreezable)
   at System.Windows.Freezable.GetCurrentValueAsFrozen()
   at System.Windows.Media.Animation.Clock..ctor(Timeline timeline)
   at System.Windows.Media.Animation.TimelineGroup.AllocateClock()
   at System.Windows.Media.Animation.Clock.AllocateClock(Timeline timeline, Boolean hasControllableRoot)"


There are three reasons why a Freezable cannot be frozen:

  • It has animated or data bound properties.
  • It has properties that are set by a dynamic resource.
  • It contains Freezable sub-objects that cannot be frozen.

So, first find out which Freezable is causing trouble and then check the above.

Need Your Help

Why is my mongodb call so slow?

javascript database node.js mongodb mongoose

Alright, so I'm building an application based in Node.js and I am using mongoose to handle my connection to mongodb. I have an endpoint that is such:

Centering a Display:inline; element

css alignment center inline

I can´t center this element. I believe it is because of display:inline; in the CSS block. Does anyone have an idea?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.