0

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.

4

1 回答 1

1

我不确定你到底在问什么,但似乎你希望能够为已经处理的事件被调用。

尝试这个:

在构造函数后面的代码中InitializeComponent(),调用

this.AddHandler(RoutedEvent, Delegate, bool);

传入事件(MouseDown或等)、要调用的委托(类似于lb1_MouseDown),然后true表明您希望为已处理的事件调用。

于 2009-04-17T16:46:28.700 回答