Viewport 3D WPF C#

David picture David · Dec 3, 2009 · Viewed 8.8k times · Source

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?

Answer

Dave3D picture Dave3D · Dec 3, 2009

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.