0
我想改變這一切材料顏色使用此代碼視圖口3D:麻煩的GetEnumerator在WPF C#
DiffuseMaterial mat = new DiffuseMaterial(new SolidColorBrush(Colors.Red));
foreach (ModelVisual3D model3d in previewport.Children)
{
foreach (GeometryModel3D item in model3d.Content)
{
item.Material = mat;
}
}
但得到的錯誤:
Error
foreach statement cannot operate on variables of type 'System.Windows.Media.Media3D.Model3D' because 'System.Windows.Media.Media3D.Model3D' does not contain a public definition for 'GetEnumerator'
請幫助。 謝謝。
你不應該使用model3d.Children代替model3d.Content? – Nitin
@SmartMan,你的意思是:'(model3d.Content as GeometryModel3D).Material = mat;'而不是內部的'foreach'循環? – dkozl
@SmartMan,如果之前添加:if(model3d.Content!= null && model3d.Content is GeometryModel3D)(model3d.Content as GeometryModel3D).Material = mat;' – dkozl