在画布内时,Viewport3D ModelVisuals3D不可见 [英] Viewport3D ModelVisuals3D not visible when inside Canvas

查看:146
本文介绍了在画布内时,Viewport3D ModelVisuals3D不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

推荐答案

我认为ViewPort3D最终将以Width和Height为0的形式在Canvas的左上角结束,因为Canvas从不拉伸其子级.尝试在选择的位置添加Canvas.Left和Canvas.Top,然后为Viewport3D添加Width和Height.如果您希望Viewport3D始终填充可用空间,那么使用Canvas是错误的方法.

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>

这篇关于在画布内时,Viewport3D ModelVisuals3D不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆