如果我将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>
答案 0 :(得分:0)
我认为ViewPort3D最终会出现在Canvas的左上角,其宽度和高度为0,因为Canvas永远不会伸展它的Children。尝试在选择的位置添加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>