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.

 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.

情況TemplatedParent可能無法null包括點擊測試特定低階的輸入事件,逐一查看與視覺化樹狀結構的事件處理等作業VisualTreeHelper,或使用列舉值,這可能會傳回來源的項目從範本。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.