0

如果我将 viewport3D 放在 Canvas 中,我的 viewport3D 将不再可见。如果我删除 Canvas,那么 Viewport3D 将再次可见。我做错了什么?

          <Canvas  Width="900" Height="524">
            <Viewport3D Name="mainViewport" ClipToBounds="True" HitTestVisible="False">
                        <Viewport3D.Camera>
                            <PerspectiveCamera 
                              FarPlaneDistance="3500"
                              LookDirection="0,0,1"
                              UpDirection="0,1,0"
                              NearPlaneDistance="1" 
                              Position="0,0,0" 
                              FieldOfView="66" />
                        </Viewport3D.Camera>
                        <ModelVisual3D>
                            <ModelVisual3D.Content>
                                <AmbientLight Color="White" />
                            </ModelVisual3D.Content>
                        </ModelVisual3D>
                    </Viewport3D>
            </Canvas>
4

1 回答 1

0

我认为 ViewPort3D 最终会出现在画布的左上角,宽度和高度为 0,因为画布从不拉伸其子项。尝试在您选择的位置添加 Canvas.Left 和 Canvas.Top,然后为您的 Viewport3D 添加宽度和高度。如果您希望 Viewport3D 始终填充可用空间,那么 Canvas 是错误的方法。

<Canvas Width="900" Height="524">
    <Viewport3D Canvas.Left="100"
                Canvas.Top="100"
                Width="200"
                Height="200"
                Name="mainViewport"
                ClipToBounds="True" 
                IsHitTestVisible="False">
        <Viewport3D.Camera>
            <PerspectiveCamera  
                        FarPlaneDistance="3500" 
                        LookDirection="0,0,1" 
                        UpDirection="0,1,0" 
                        NearPlaneDistance="1"  
                        Position="0,0,0"  
                        FieldOfView="66" />
        </Viewport3D.Camera>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <AmbientLight Color="White" />
            </ModelVisual3D.Content>
        </ModelVisual3D>
    </Viewport3D>
</Canvas>
于 2010-11-05T12:52:06.533 回答