0

starting from a basic HelixToolkit example, I am able to render a mesh. In my .xaml file:

 <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:

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. How can I do that?

Nic
  • 1,262
  • 2
  • 22
  • 42

1 Answers1

0

I finally managed to solve the issue using a 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.

this.Model = myNewModelGroup;
OnPropertyChanged("Model");
Nic
  • 1,262
  • 2
  • 22
  • 42