2012-03-18 19 views
2

我希望我的標題是明確....在設置XAML中元素的內容時,WPF如何確定要設置的屬性?

我的意思是〔實施例當我們定義動畫:

的XAML:

<StoryBoard> 
    <DoubleAnimation..../> 
</StoryBoard> 

但是,如果我們定義了同樣的事情的代碼隱藏我們可以這樣做:

DoubleAnimation myDAnimation = new DoubleAnimation(); 
..... 
StoryBoard myStoryBoard = new StoryBoard(); 
myStoryBoard.Children.Add(myDAnimation); 

我試圖尋找到故事板的類定義,沒有什麼特別的:

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是應該添加到StoryBoardChildren屬性? 如果我需要做同樣的事情,我需要申報什麼?

回答

4

有該屬性:ContentPropertyAttribute

如果你檢查類的Syntax部分MSDN上你可以看到什麼屬性將指定內容時進行設置。例如。 ContentControl的目標是Content屬性。

+0

啊,謝謝,我明白了。我一直認爲這是構造函數。不知道這是屬性......這就是爲什麼這些Button等控件我可以簡單地在他們的定義中定義另一個控件。 +1(需要3分鐘再接受答案...) – 2012-03-18 19:47:45

1

TimelineGroupStoryboard祖先具有Children屬性和它也有ContentPropertyAttribute其指定Children屬性作爲內容屬性。

+0

+1這對我來說也是正確的答案,謝謝〜 – 2012-03-18 19:53:16

相關問題