单击图形节点时获取节点名称

时间:2020-05-14 05:26:31

标签: c# wpf graphviz

我现在正在使用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”获取“被舔节点”对象,然后突出显示该对象

enter image description here

但是现在我会得到节点的名称(即图片中的A和B)。反正有这样做吗?

1 个答案:

答案 0 :(得分:0)

我找到了解决我的问题的解决方案。

PdfDictionary _pd = signatureUtil.GetSignatureDictionary("Signature1");
pd.Put(PdfName.Contents, new PdfString(paddedSig).SetHexWriting(true));

pdfDocument.Close();

因此完整的源代码如下所示

 byte[] _p7s = System.IO.File.ReadAllBytes("tmp/example.p7s");

 private static void Embed_P7S(Org.BouncyCastle.X509.X509Certificate[] _chain, byte[] _p7s)
    {
        PdfDocument document = new PdfDocument(new PdfReader("results/example-prepared.pdf"));
        Stream output = new FileStream("results/example-prepared-signed.pdf", FileMode.Create);

        ExternalInjectingSignatureContainer container2 = new ExternalInjectingSignatureContainer(_p7s);

        PdfSigner.SignDeferred(document, "Signature1", output, container2);
    }
}


internal class ExternalInjectingSignatureContainer :IExternalSignatureContainer
{
    public ExternalInjectingSignatureContainer(byte[] signature)
    {
        Signature = signature;
    }

    public void ModifySigningDictionary(PdfDictionary signDic)
    {
    }

    public byte[] Sign(Stream data)
    {
        return Signature;
    }

    public byte[] Signature;
}