简体   繁体   English

如何刷新按钮上的HelixToolkit ModelVisual3D内容?

[英]How to refresh HelixToolkit ModelVisual3D content on pressed button?

starting from a basic HelixToolkit example, I am able to render a mesh. 从基本的HelixToolkit示例开始,我能够渲染网格。 In my .xaml file: 在我的.xaml文件中:

 <HelixToolkit:HelixViewport3D Name ="viewPort" ZoomExtentsWhenLoaded="True">        
 <HelixToolkit:SunLight/>
 <!--The content of this visual is defined in MainViewModel.cs--> 
 <ModelVisual3D Content="{Binding Model}"/> 

And in my .cs file: 在我的.cs文件中:

Model3DGroup modelGroup = new Model3DGroup();            
// [... add stuff to modelGroup  as children ]
this.Model = modelGroup;

Now, I try to modify my rendered objects when a button is clicked. 现在,我尝试在单击按钮时修改渲染的对象。 I tried to implement it through a callback function by updating the model. 我试图通过更新模型通过回调函数实现它。

public void testUpdate(){
       Model3DGroup newModelGroup = new Model3DGroup();            
       // [... add stuff to newModelGroup  as children ]
       this.Model = newModelGroup;
    }

This doesn't work: the shown objects are not those added to newModelGroup. 这不起作用:显示的对象不是添加到newModelGroup的对象。 How can I do that? 我怎样才能做到这一点?

I finally managed to solve the issue using a PropertyChangedEventHandler 我终于设法使用PropertyChangedEventHandler解决了这个问题

public event PropertyChangedEventHandler PropertyChanged;

private void OnPropertyChanged(string propertyName) {
   if (PropertyChanged != null)
        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
   }
}

Every time the Model is modified, the OnPropertyChangedMethod is called so the new modifications are corectly rendered. 每次修改Model时,都会调用OnPropertyChangedMethod,以便核心地呈现新的修改。

this.Model = myNewModelGroup;
OnPropertyChanged("Model");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM