Associate data with Visual3d objects
#2
In WPF most of the objects are derived from DependencyObject (ModelVisual3D and other Visual3D objects from Ab3d.PowerToys are also derived from that class). This means that you can add any DependencyProperty to the object.

For example if you want to add your own class, for example ModelDetails, to a TubeVisual3D, you will first need to define a new DependencyProperty that will hold the ModelDetails:

Code:
class ModelDetails
{
// ... some other code

public static readonly DependencyProperty ModelDetailsProperty = DependencyProperty.Register("ModelDetails", typeof(ModelDetails), typeof(ModelDetails));

// ... some other code
}

This will define the ModelDetailsProperty inside the ModelDetails class. Note that in Register method the first typeof defines the type of the DependencyProperty and the second typeof defines the owner type.

After that you can assign the ModelDetails to an instance of TubeVisual3D (or any other DependencyObject) with using SetValue:

Code:
myTubeVisual.SetValue(ModelDetails.ModelDetailsProperty, myTubeVisualModelDetails);

Then in your click event handler you can read the data with GetValue method:

Code:
var clickedModelDetails = clickedVisual3D.GetValue(ModelDetails.ModelDetailsProperty) as ModelDetails;
Andrej Benedik
  


Messages In This Thread
Associate data with Visual3d objects - by MQM - 04-27-2017, 07:21 PM
RE: Associate data with Visual3d objects - by abenedik - 04-27-2017, 09:14 PM
RE: Associate data with Visual3d objects - by MQM - 04-27-2017, 10:02 PM

Forum Jump:


Users browsing this thread:
1 Guest(s)