问题
I found on the Helix Toolkit an example, which is called to ScatterPlot, which is really close what I really need. But I can't find anything about how can I add something onclick event listener to the created objects (in this case to the sphere). This adds the sphere to the 'playground'.
scatterMeshBuilder.AddSphere(Points[i], SphereSize, 4, 4);
The basic goal is to add every sphere an onclick event listener and when the user choose a color and click one of these spheres it will change to the selected color. It's possible to add onclick listener (or something equal with it) to the spheres.
回答1:
One year later... Maybe someone will find this usefull.
A solution that worked for me revolves around extending the UIElement3D class, this has a bunch of standard events that you can override. e.g MouseEnter,MouseClick etc. Source below.
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using System.Windows.Controls.Primitives;
using System.Windows.Controls;
public class InteractivePoint : UIElement3D
{
public InteractivePoint(Point3D center, Material material, double sphereSize = 0.07)
{
MeshBuilder builder = new MeshBuilder();
builder.AddSphere( center, sphereSize , 4, 4 );
GeometryModel3D model = new GeometryModel3D( builder.ToMesh(), material );
Visual3DModel = model;
}
protected override void OnMouseEnter( MouseEventArgs event )
{
base.OnMouseEnter( event );
GeometryModel3D point = Visual3DModel as GeometryModel3D;
point.Material = Materials.Red; //change mat to red on mouse enter
Event.Handled = true;
}
protected override void OnMouseLeave( MouseEventArgs event )
{
base.OnMouseEnter( event );
GeometryModel3D point = Visual3DModel as GeometryModel3D;
point.Material = Materials.Blue; //change mat to blue on mouse leave
Event.Handled = true;
}
}
To add them to the playground
Point3D[,] dataPoints = new Point3D[10,10]; // i will assume this has already been populated.
ContainerUIElement3D container;
Material defaultMaterial = Materaials.Blue;
for (int x = 0;x < 10; x++)
{
for(int y = 0; y < 10; y++)
{
Point3D position = dataPoints [x, y];
InteractivePoint interactivePoint = new InteractivePoint( position, defaultMaterial );
container.Children.Add( interactivePoint );
}
}
Finally add the container as a child to a ModelVisual3D object.
来源:https://stackoverflow.com/questions/27569202/create-clickable-objects-with-helix-toolkit