WPF:如何沿着可视化树查找单击的 3D 模型所在的 Model3DGroup?
我将一些 3D 模型显示为 Model3DGroup。 它们被捕获 MouseDown 事件的 Viewport3D 包围。
我想确定单击了哪个 Model3DGroup(它们都有名称)。 我从这里开始:
Point location = e.GetPosition(karte.ZAM3DViewport3D);
HitTestResult hitResult = VisualTreeHelper.HitTest(karte.ZAM3DViewport3D, location);
if (hitResult != null )
{
Debug.WriteLine("BREAKPOINT");
// Hit the visual.
}
在命中 WriteLine 命令中设置的断点后,我正在查看本地视图以找到正确的变量,但找不到它。 你能帮我看看我需要走哪条路才能找到 modelvisual3d 所属的组吗?
这是树的屏幕截图:
I'm displaying a few 3D-models as Model3DGroups.
They are surrounded by Viewport3D which catches MouseDown-events.
I want to determine which Model3DGroup (they all have names) was clicked.
I'm starting with this:
Point location = e.GetPosition(karte.ZAM3DViewport3D);
HitTestResult hitResult = VisualTreeHelper.HitTest(karte.ZAM3DViewport3D, location);
if (hitResult != null )
{
Debug.WriteLine("BREAKPOINT");
// Hit the visual.
}
After hitting the breakpoint set at the WriteLine-command I'm looking at the local-view to find the right variable but can't find it.
Can you help me out which path I need to take to find the group, the modelvisual3d belongs to?
Here is a screenshot of the tree:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过使用 ModelUIElement3D 围绕 Model3DGroup 来完成此操作。
MouseDown 函数以这种方式处理它:
I did it by surrounding the Model3DGroup with a ModelUIElement3D.
the MouseDown-function handles it this way:
您可以使用 Linq to Visual Tree 作为您要查找的命名元素是否为 Model3DGroup 并不重要。它只是另一个依赖对象(如果我理解你的问题)。
检查结果的类型,然后 LinqToVT 向上,检索它的 XAML 前身:
You could use Linq to Visual Tree as it doesn't matter whether the named element you are looking for is Model3DGroup. It is just another Dependency Object (if I understand your question).
Check result's type and then LinqToVT to go up, retrieving it's XAML predecessor: