UserControl and Attached Event
-
Greetings good people, I have a user control that I place in my main grid (LayoutRoot) that handles the layout for the window. There are several buttons in the main grid (LayoutRoot) that serve different purposes depending on what's loaded in the main content area. The button's function and purpose depends on which user control is loaded. In turn, the user control has to perform several actions in response to which specific multipurpose button was pressed. I am trying to use an attached event to coordinate these activities. How do I get the user control to know which multipurpose button was clicked; and then have one of the user control's constituent elements undertake some actions in response to the event (e.g. button click)? Thanks, Blitz
-
Greetings good people, I have a user control that I place in my main grid (LayoutRoot) that handles the layout for the window. There are several buttons in the main grid (LayoutRoot) that serve different purposes depending on what's loaded in the main content area. The button's function and purpose depends on which user control is loaded. In turn, the user control has to perform several actions in response to which specific multipurpose button was pressed. I am trying to use an attached event to coordinate these activities. How do I get the user control to know which multipurpose button was clicked; and then have one of the user control's constituent elements undertake some actions in response to the event (e.g. button click)? Thanks, Blitz
Can you use RoutedEvents? It should tunnel down to your usercontrol where you can take action.
-
Can you use RoutedEvents? It should tunnel down to your usercontrol where you can take action.
Thanks for replying. Indeed I am trying that approach. However, the buttons are children of the main grid. The user control is also a child of the main grid. I don't think, therefore, they share the same visual or logical tree. Thus far, it seems that the button click events travel all the way up to the main grid. It doesn't seem as if my user control can hear the button click events. Any thoughts?
-
Thanks for replying. Indeed I am trying that approach. However, the buttons are children of the main grid. The user control is also a child of the main grid. I don't think, therefore, they share the same visual or logical tree. Thus far, it seems that the button click events travel all the way up to the main grid. It doesn't seem as if my user control can hear the button click events. Any thoughts?
How about bubbling the button clicks up. Catching them on the LayoutGrid then raise a new tunneling event, which is sent down to your usercontrol. Not sure if this is a good idea, maybe somebody else will chime in.