我希望我的头衔清楚......
当我们定义动画时,我的意思是exmaple:
的Xaml:
<StoryBoard>
<DoubleAnimation..../>
</StoryBoard>
但是如果我们在代码隐藏中定义相同的东西,我们可以这样做:
DoubleAnimation myDAnimation = new DoubleAnimation();
.....
StoryBoard myStoryBoard = new StoryBoard();
myStoryBoard.Children.Add(myDAnimation);
我试着看看StoryBoard的类定义,没什么特别的:
public sealed class Storyboard : Timeline
{
public Storyboard();
// Summary:
// Gets the collection of child System.Windows.Media.Animation.Timeline objects.
//
// Returns:
// The collection of child System.Windows.Media.Animation.Timeline objects.
// The default is an empty collection.
public TimelineCollection Children { get; }
....
}
我知道如果我用上面的sytnax定义我自己的类,为了加入我的孩子,我需要:
XAML:
<MyClass>
<MyClass.Children>
<MyClassCildrenItem..../>
</MyClass.Children>
</MyClass>
那么Xaml是如何知道DoubleAnimation
应该添加到StoryBoard
的{{1}}属性中的呢?
如果我需要做同样的事情,我需要申报什么?
答案 0 :(得分:5)
有一个属性:ContentPropertyAttribute
如果您检查MSDN上的类的Syntax
部分,您可以看到在指定内容时将设置哪些属性。例如。 ContentControl
定位Content
属性。
答案 1 :(得分:1)
TimelineGroup Storyboard
的祖先具有Children
属性,并且还ContentPropertyAttribute指定Children
属性作为内容属性。