richardaum
richardaum

Reputation: 6777

Silverlight - Parent of an element

Now I have a question a little more complicated.

How do I get the parent element of an object.

For example:

<Viewbox>
<TextBlock Name="txtblock1" />
</Viewbox>

How do i get, via code (c#), the parent element of "txtblock1" ?

Upvotes: 1

Views: 711

Answers (1)

Praetorian
Praetorian

Reputation: 109189

Use the Parent property. The parent is returned as an Object so you'll need to cast it to be able to call Viewbox's methods.

For example:

var vbox = txtblock1.Parent as Viewbox;
if( vbox != null ) {
  // do something with vbox
}

Upvotes: 2

Related Questions