user1371933
user1371933

Reputation: 1

Get Element inside Element (parent/child) WPF

I have got a question about accessing elements inside another element.

The situation

<grid name=container>
    <grid name=menu >
       inside here is the menu
    </grid
 <button />
<grid>

If the button is pressed the second grid (with the menu) needs to hide. How do i access the grid element when pressing the button. This needs to be without use of the actual name of the grid because it's in a data-template and multiple objects make use of that same template, but only the actual active one needs to hide.

Upvotes: 0

Views: 1978

Answers (1)

Tilak
Tilak

Reputation: 30698

RoutedEventArgs class has Source, OriginalSource properties which can be used to determine the required information. In addition sender argument is also available in the event handler.

Following link explains the difference (and also answers the question), in Source, OriginalSource, and Sender. RoutedEventArgs.Source vs Sender

RoutedEventArgs.OriginalSource - original object that first raised the event

RoutedEventArgs.Source - object that raised event. This is usually the same as OriginalSource but when dealing with Composite Controls it can be the parent that contains the OriginalSource object.*

Sender - Current element that is handling the event

Upvotes: 1

Related Questions