问题
Can you please show how to set and save the background color of the viewport3D. Whenever I save no background is visible only model, I tried the grid but that gets everything in the grid? Any help will do?
回答1:
Viewport3D doesn't have a Background property so you need something behind it.
your approach using a Grid is right, you might want to use a Border to enforce the use of a single child.
<Border Background="Green">
<Viewport3D Width="640.0" Height="480.0" >
<ModelVisual3D/>
</Viewport3D>
</Border>
I assume you are using XamlWriter, XamlReader . Just save the border instead of the Viewport3D and everything inside the border will be saved as well.
回答2:
I have provided some code for this, please verify it.
<Viewport3D>
<Viewport3D.Camera>
<PerspectiveCamera Position="2,0,10" LookDirection="0.2,0.4,-1" FieldOfView="65" UpDirection="0,1,0">
</PerspectiveCamera>
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup>
<AmbientLight Color="#fff"/>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="0,0,0 0,10,0 10,0,0 10,10,0"
Normals="0,0,1 0,0,1 0,0,1 0,0,1"
TriangleIndices="0,2,1,1,2,3"/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial Brush="Red"/>
</GeometryModel3D.Material>
</GeometryModel3D>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
来源:https://stackoverflow.com/questions/1841489/viewport-3d-wpf-c-sharp