Viewport3D ModelVisuals3D not visible when inside Canvas

天涯浪子 提交于 2019-12-02 14:32:36

问题


If I put viewport3D inside Canvas my viewport3D is not visible anymore. If I remove Canvas then Viewport3D is visible again. What I'm doing wrong?

          <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>

回答1:


I think the ViewPort3D will end up in the upper left corner of the Canvas with a Width and Height of 0 since Canvas never stretches its Children. Try to add Canvas.Left and Canvas.Top at the positioning of your choise and then add Width and Height for your Viewport3D. If you want your Viewport3D to always fill the available space then Canvas is the wrong way to go.

<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>


来源:https://stackoverflow.com/questions/4097428/viewport3d-modelvisuals3d-not-visible-when-inside-canvas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!