views:

322

answers:

2

Hi,

A very well known fact is that routed events only travel up or down the ancestry and not through all the elements.

But an equally known fact is that an event handler can be wired in the common parent of two disparate controls.

My questions is how, some pointers please.

I have XAML that looks like

<Grid Name="MainGrid">
    <Listbox Name="lb1"/>
    <Grid Name="InnerGrid">
       <Listbox Name="lb2"/>
    </Grid>
</Grid>

The Mouse Event handlers defined on "lb1" will not get fired as it gets "burried" under "InnerGrid". My question is how can I wrote some code in the "MainGrid" or somewhere else wherein the event handlers defined on "lb1" get fired. Or may be some other technique of achieveing this.

Many Thanks.

A: 

This might be a stupid question, but why do you "bury" your lb1 under the InnerGrid in the first place? ;)

Christian Hubmann
Your question absolutely makes sense. The question I asked above is something like cutting long story short. Basically at 1024X768 the screen real estate is not too accommodating and there are lots of controls in that form. :)
Anand
+1  A: 

I'm not sure exactly what you are asking, but it seems you want to be able to get called for events that have already been handled.

Try this:

In your code behind in the constructor after InitializeComponent(), call

this.AddHandler(RoutedEvent, Delegate, bool);

Pass in the event (MouseDown or etc), the delegate to call (something like lb1_MouseDown), and then true to indicate that you want to be called for events that have already been handled.

Josh G