views:

358

answers:

1

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"
                                      Storyboard.TargetName="GreenBelow"
                                      Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)">
            <SplineColorKeyFrame KeyTime="00:00:00"
                                 Value="#FF75F45D" />
            <SplineColorKeyFrame KeyTime="00:00:00.1000000"
                                 Value="#FFA5F796" />
            <SplineColorKeyFrame KeySpline="1,0,1,0.06"
                                 KeyTime="00:00:00.5000000"
                                 Value="#FF75F45D" />
        </ColorAnimationUsingKeyFrames>
</Storyboard>

Here is what i have in XAML

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

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.

+1  A: 

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.

AnthonyWJones