使用Helix工具包创建可点击对象 [英] Create clickable objects with helix toolkit

查看:150
本文介绍了使用Helix工具包创建可点击对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Helix Toolkit上找到了一个示例,该示例称为ScatterPlot,与我真正需要的确实很接近.但是我找不到关于如何向创建的对象(在本例中为球形)添加onclick事件侦听器的任何信息.这会将球体添加到游乐场".

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);

基本目标是为每个球体添加onclick事件侦听器,并且当用户选择一种颜色并单击这些球体之一时,它将变为所选颜色.可以向这些球体添加onclick侦听器(或与其等效的东西).

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.

推荐答案

一年后……也许有人会觉得这个有用.

One year later... Maybe someone will find this usefull.

一个对我有用的解决方案围绕着扩展 UIElement3D 类,它具有一堆您可以覆盖的标准事件.例如MouseEnter,MouseClick等. 来源如下.

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;
    }


}

将它们添加到操场上

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 );
    }
}

最后将容器作为子容器添加到ModelVisual3D对象.

Finally add the container as a child to a ModelVisual3D object.

这篇关于使用Helix工具包创建可点击对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆