views:

26

answers:

2

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: alt text

+1  A: 

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:

hitResult.VisualHit.GetType() == typeof(ModelVisual3D)
Aggelos Mpimpoudis
I avoided LINQ until today, but I guess its time to work with it.I could use a workaround for my problem by encapsulating a Model3DGroup within a ModelUIElement3D which also can trigger Mouse-Events.
Hedge
A: 

I did it by surrounding the Model3DGroup with a ModelUIElement3D.

<ModelUIElement3D MouseDown="ModelUIElement3D_MouseDown" x:Name="LogoMouseDown">

the MouseDown-function handles it this way:

    private void ModelUIElement3D_MouseDown(object sender, MouseButtonEventArgs e)
    {

            if (sender == trololo)
            {
                RaiseModelClickEvent("auditorium");    
            }
            else if (sender == LogoMouseDown)
            {
                RaiseModelClickEvent("logo");
            }

    }
Hedge