[英]How does WPF determine what property to set when setting the content of elements in XAML?
我希望我的头衔清楚。
我的意思是当我们定义动画时的例子:
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定义了自己的课程,为了添加到我的Children中,我需要:
XAML:
<MyClass>
<MyClass.Children>
<MyClassCildrenItem..../>
</MyClass.Children>
</MyClass>
那么Xaml如何知道DoubleAnimation
应该添加到StoryBoard
的Children
属性中? 如果我需要做同样的事情,我需要声明什么?
有一个属性: ContentPropertyAttribute
如果您在MSDN上检查类的“ Syntax
部分,则可以看到在指定内容时将设置哪些属性。 例如, ContentControl
以Content
属性为目标。
TimelineGroup的祖先Storyboard
有Children
性,它也有ContentPropertyAttribute指定的Children
财产为内容属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.