이 페이지가 유용했습니까?
이 콘텐츠에 대한 여러분의 의견은 중요합니다. 의견을 알려주십시오.
추가 의견
1500자 남음
내보내기(0) 인쇄
모두 확장

FrameworkElement.Parent 속성

Gets the logical parent element of this element.

네임스페이스: System.Windows
어셈블리: PresentationFramework(presentationframework.dll)
XML 네임스페이스:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public DependencyObject Parent { get; }
/** @property */
public DependencyObject get_Parent ()

public function get Parent () : DependencyObject

이 속성은 XAML에서 사용할 수 없습니다.

속성 값

This element's logical parent.

Parent may be null 참조(Visual Basic의 경우 Nothing) in cases where an element was instantiated, but is not attached to any logical tree that eventually connects to the page level root element, or the application object.

Note that the logical parent of an element can potentially change depending on your application's functionality, and keeping the value of this property will not reflect that change. You typically should get the value immediately before you need it.

See Element Tree for more information about logical tree traversal, and the scenarios where using Parent as a technique of parent element discovery is appropriate.

The property engine will potentially recalculate all property values of an element when it is reparented, because some properties inherit values through the logical tree. The DataContext that applies for bindings can also change when elements are reparented.

Changing an element's parent is typically only done through manipulation of collections, by using dedicated add or remove methods, or through setting content properties of elements.

The most typical scenario for using the Parent property is to obtain a reference and then get various FrameworkElement property values from the parent. For templates, the Parent of the template eventually will be null 참조(Visual Basic의 경우 Nothing). To get past this point and extend into the logical tree where the template is actually applied, use TemplatedParent.

Note that this property does not report visual tree parents in cases where these vary from the logical tree parents. Visual tree parents are not typically important for general application cases but may be the desired parent elements for certain visual level cases. See VisualTreeHelper.

The following example shows code that checks for an element's parent, and then uses property values from the parent to set properties on the child element to match. In this case these are properties that affect the rendering size.

private void OnUIReady(object sender, System.EventArgs e)
{
    LinePane.Width = ((StackPanel)LinePane.Parent).ActualWidth;
    LinePane.Height = ((StackPanel)LinePane.Parent).ActualHeight;
    DesignerPane.MouseLeave += new System.Windows.Input.MouseEventHandler(DesignerPane_MouseLeave);
    this.SizeChanged += new SizeChangedEventHandler(Window1_SizeChanged);
}

Microsoft .NET Framework 3.0은 Windows Vista, Microsoft Windows XP SP2 및 Windows Server 2003 SP1에서 지원됩니다.

.NET Framework

3.0에서 지원

커뮤니티 추가 항목

추가
표시:
© 2015 Microsoft