【发布时间】:2020-08-30 13:09:19
【问题描述】:
我现在正在使用 dotviewer 项目。当用户单击节点时,我尝试获取节点的名称。 在此处参考 dotviewer 项目:https://www.codeproject.com/Articles/18870/Dot2WPF-a-WPF-control-for-viewing-Dot-graphs
我检测到当用户点击一个节点时,该节点被下面的代码突出显示
void MouseLeftButtonDownHandler(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
ToolTipController.Hide();
// Retreive the coordinates of the mouse button event.
Point pt = e.GetPosition(this);
DrawingVisual hit = VisualTreeHelper.HitTest(this, pt).VisualHit as DrawingVisual;
if (hit != null)
{
string tag = hit.ReadLocalValue(FrameworkElement.TagProperty) as string;
if (tag != null)
{
foreach (DrawingVisual v in _graph.Children)
{
v.BitmapEffect = null;
}
OuterGlowBitmapEffect glow = new OuterGlowBitmapEffect();
glow.GlowColor = Colors.Blue;
glow.GlowSize = 1;
glow.Opacity = 0.8;
glow.Freeze();
hit.BitmapEffect = glow;
}
}
}
代码使用“hit”获取“被舔过的节点”对象,然后高亮显示它
但现在我会得到节点的名称(即图片中的 A 和 B)。有什么办法吗?
【问题讨论】:
-
你检查过
sender是什么吗? -
sender 是这个当前类(Rodemeyer.Visualizing.GraphElement 类),我找不到类似名称属性的东西