So I would like to move my Storyboards into a ResourceDictionary file and I am having trouble doing that. I have looked everywhere and it involves making the "Resource" sharable but how do I do that in silverlight when there is no x:Shared attribute. Here is the code

 <Storyboard x:Key="GreenButtonLight"  >
        <ColorAnimationUsingKeyFrames BeginTime="00:00:00"
            <SplineColorKeyFrame KeyTime="00:00:00"
                                 Value="#FF75F45D" />
            <SplineColorKeyFrame KeyTime="00:00:00.1000000"
                                 Value="#FFA5F796" />
            <SplineColorKeyFrame KeySpline="1,0,1,0.06"
                                 Value="#FF75F45D" />

Here is what i have in XAML

        <ResourceDictionary Source="Resources/ViewResources.xaml" />

and here is the Error That i get

Error: Element is already the child of another element.

It only gives me that error when I put in storyboards, nothing else (ex:Styles). I am using Silverlight 3 and not wpf.

Was it helpful?


You can't place a storyboard in a resource because its a stateful object. It knows whether it has begun animating, where it is in the timeline etc. Also its child animations acquire a references to the objects and properties they are animating.

Typically one places storyboards to be reused in the VisualStateManager of an element in control template.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow