ModelVisual3D.Content
is a single System.Windows.Media.Media3D
object and that why it's complaining about foreach
loop. Instead of the inner loop just cast Content
as GeometryModel3D
and change its Material
like below:
DiffuseMaterial mat = new DiffuseMaterial(new SolidColorBrush(Colors.Red));
foreach (ModelVisual3D model3d in previewport.Children)
{
var geometryModel = model3d.Content as GeometryModel3D;
if (geometryModel != null) geometryModel.Material = mat;
}