本文介绍了ResourceDictionary 中的故事板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想将我的故事板移动到一个 ResourceDictionary 文件中,但我在这样做时遇到了麻烦.我到处寻找,它涉及使资源"可共享,但是当没有 x:Shared 属性时,我如何在 Silverlight 中做到这一点.这是代码

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>

这是我在 XAML 中的内容

Here is what i have in XAML

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

这是我得到的错误

错误:元素已经是另一个元素的子元素.

Error: Element is already the child of another element.

当我放入故事板时,它只会给我这个错误,没有别的(例如:样式).我使用的是 Silverlight 3 而不是 wpf.

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

推荐答案

您不能在资源中放置故事板,因为它是一个有状态的对象.它知道它是否已经开始动画,它在时间轴中的位置等等.而且它的子动画获取对它们正在动画的对象和属性的引用.

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.

通常会在控件模板中的元素的 VisualStateManager 中放置要重用的故事板.

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

这篇关于ResourceDictionary 中的故事板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 18:16