从基本的HelixToolkit示例开始,我能够渲染一个网格物体。在我的.xaml文件中:
<HelixToolkit:HelixViewport3D Name ="viewPort" ZoomExtentsWhenLoaded="True">
<HelixToolkit:SunLight/>
<!--The content of this visual is defined in MainViewModel.cs-->
<ModelVisual3D Content="{Binding Model}"/>
在我的.cs文件中:
Model3DGroup modelGroup = new Model3DGroup();
// [... add stuff to modelGroup as children ]
this.Model = modelGroup;
现在,我尝试在单击按钮时修改渲染的对象。我尝试通过更新模型通过回调函数实现它。
public void testUpdate(){
Model3DGroup newModelGroup = new Model3DGroup();
// [... add stuff to newModelGroup as children ]
this.Model = newModelGroup;
}
这不起作用:显示的对象不是添加到newModelGroup的对象。我怎么能这样做?
答案 0 :(得分:0)
我终于设法使用PropertyChangedEventHandler
解决了这个问题public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName) {
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
每次修改模型时,都会调用OnPropertyChangedMethod,以便对其进行核心渲染。
this.Model = myNewModelGroup;
OnPropertyChanged("Model");