Storyboards in ResourceDictionary

帅比萌擦擦* 提交于 2019-12-11 08:10:00

问题


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:


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.



来源:https://stackoverflow.com/questions/2543109/storyboards-in-resourcedictionary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!