我正在尝试解决以下问题:
我有一个 3 行 1 列的网格。每个单元格都有一些子控件。此外,我还可以控制跨越整个 3 行的内容,类似于“覆盖”,我在整个网格上渲染一些视觉效果。我需要对此覆盖层以及子控件进行命中测试。
然而,由于逻辑/可视树的构造方式,覆盖层的父级是网格而不是其子级(它们在树中与覆盖层处于同一级别)。
我如何构建 WPF 树,以便事件向上冒泡到网格的其他控件。
该树看起来像这样:
Grid
- Row 1 Control
- Row 2 Control
- Row 3 Control
- Overlay (Row 1 - 3) Control
如果覆盖层不处理事件,我需要在第 1/2/3 行控件中处理它。我希望我的问题很清楚。
I am trying to wrap my head around the following problem:
I have a Grid with 3 rows, 1 column. Each of the cells have some sub controls. Additionally, I have on control which spans the entire 3 rows, something like an "overlay" where I render some visuals across the entire Grid. I need hit testing on this overlay as well as on the sub controls.
However, due to how the logical/visual tree is constructed, the parent of the overlay is the Grid and not its children (which are on the same level in the tree as the overlay).
How could I construct the WPF tree, so that the events bubble up to the other controls of the Grid.
The tree looks something like this:
Grid
- Row 1 Control
- Row 2 Control
- Row 3 Control
- Overlay (Row 1 - 3) Control
If the overlay does not handle an event, I need to handle it in the Row 1/2/3 controls. I hope my question is clear.
发布评论
评论(1)
使用 命中测试的支持://msdn.microsoft.com/en-us/library/ms608753.aspx" rel="nofollow">
VisualTreeHelper.HitTest
。Have a look at WPF's support for hittesting using
VisualTreeHelper.HitTest
.