FrameworkElement.TemplatedParent FrameworkElement.TemplatedParent FrameworkElement.TemplatedParent FrameworkElement.TemplatedParent Property

定義

取得這個項目的範本父代參考。Gets a reference to the template parent of this element. 如果項目不是透過範本建立,則這個屬性無關。This property is not relevant if the element was not created through a template.

public:
 property System::Windows::DependencyObject ^ TemplatedParent { System::Windows::DependencyObject ^ get(); };
public System.Windows.DependencyObject TemplatedParent { get; }
member this.TemplatedParent : System.Windows.DependencyObject
Public ReadOnly Property TemplatedParent As DependencyObject

屬性值

此項目由其 FrameworkTemplateVisualTree 所建立。The element whose FrameworkTemplateVisualTree caused this element to be created. 這個值通常是 nullThis value is frequently null.

備註

TemplatedParent通常null是在應用程式標記或程式碼中建立的物件。TemplatedParent is frequently null for objects that are created in your application markup or code. 這是因為您是直接建立這些物件, 而不是透過範本。This is because you create those objects directly, not via a template. 藉由從根流覽邏輯樹狀結構或一般名稱參考取得的物件參考, 不是來自範本。Object references obtained by walking the logical tree from the root, or by typical name references, do not come from a template.

可能不包含作業的情況, 例如點擊測試、特定低層級輸入事件的事件處理、使用VisualTreeHelper視覺化樹狀結構, 或使用列舉值, 這可能會傳回的元素null TemplatedParent從範本。Cases where TemplatedParent might not be null include operations such as hit-testing, event handling for certain low-level input events, walking the visual tree with VisualTreeHelper, or working with enumerators, which might return elements that came from templates. 另一種情況是, 如果FindName您特別針對FrameworkTemplate現有的呼叫, 並使用傳回的物件。Another case is if you specifically call FindName against an existing FrameworkTemplate and are work with the returned object.

範本實際上是共用物件, 其中範本的內容只會建立一次。Templates are actually shared objects, where the contents of the template are created only once. 因此, 如果您取得來自範本之元素的物件參考, 您可能會發現明顯的邏輯樹狀結構無法到達頁面根目錄。Therefore, if you obtain an object reference to an element that came from a template, you may find that the apparent logical tree does not reach to the page root. 若要將這類範本參考連接到頁面的邏輯樹狀結構, 您應該取得TemplatedParent值, 並視需要繼續流覽該元素樹狀結構。In order to connect such a template reference to the page's logical tree, you should get the TemplatedParent value and continue to navigate that element tree as desired.

適用於