gpt4 book ai didi

c# - 使用 helix 工具包创建可点击对象

转载 作者:行者123 更新时间:2023-11-30 20:45:57 25 4
gpt4 key购买 nike

我在 Helix Toolkit 上找到了一个示例,它调用了 ScatterPlot,这非常接近我真正需要的。但是我找不到任何关于如何向创建的对象(在本例中为球体)添加一些 onclick 事件监听器的信息。这会将球体添加到“ Playground ”。

scatterMeshBuilder.AddSphere(Points[i], SphereSize, 4, 4);

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

最佳答案

一年后......也许有人会发现这很有用。

一个对我有用的解决方案是围绕扩展 UIElement3D类,这有一堆你可以覆盖的标准事件。例如 MouseEnter、MouseClick 等。来源如下。

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


}

将它们添加到 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 );
}
}

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

关于c# - 使用 helix 工具包创建可点击对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27569202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com