Search code examples
c#wpf3dviewport3d

How to make contextmenu appear when right-clicking on an empty space inside a Viewport3D? (C# WPF)


I've been trying to find a solution but can't. Right now my context menu appears only when I right-click on a 3d object withing the Viewprot3D. Does anyone know a solution?

   <Viewport3D Name="Scene" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="7" Margin="0,1,0,-1" Grid.RowSpan="2" ContextMenu="{StaticResource ModellingMenu}" MouseDown="Scene_MouseDown">
<!-- Your 3D content goes here -->

I had an idea that there could be a control over it that will be click-through, but Viewport3D doesn't support the property IsHitTestVisible.


Solution

  • You could wrap the Viewport3D element in a painted Panel and show the ContextMenu on this one:

    <Grid Background="Transparent" ContextMenu="{StaticResource ModellingMenu}" MouseDown="Scene_MouseDown">
        <Viewport3D ... />
    </Grid>