wpf 中的路由事件
一个众所周知的事实是,路由事件仅沿着祖先向上或向下传播,而不是穿过所有元素。
但同样众所周知的事实是,事件处理程序可以连接到两个不同控件的公共父级中。
我的问题是如何,请指点。
我的 XAML 看起来像
<Grid Name="MainGrid">
<Listbox Name="lb1"/>
<Grid Name="InnerGrid">
<Listbox Name="lb2"/>
</Grid>
</Grid>
“lb1”上定义的鼠标事件处理程序不会被触发,因为它被“埋藏”在“InnerGrid”下。 我的问题是如何在“MainGrid”或其他地方编写一些代码,其中“lb1”上定义的事件处理程序被触发。 或者可能是实现这一目标的其他技术。
非常感谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您到底在问什么,但似乎您希望能够为已经处理的事件接到电话。
试试这个:
在
InitializeComponent()
之后的构造函数后面的代码中,在事件中调用 Pass(
MouseDown
等),要调用的委托(类似于lb1_MouseDown
),然后true
表示您希望为已处理的事件调用。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()
, callPass in the event (
MouseDown
or etc), the delegate to call (something likelb1_MouseDown
), and thentrue
to indicate that you want to be called for events that have already been handled.