我正在构建一个简单的示例应用程序来测试 MSAGL,但如果我在显示图形后添加一条边,则会收到 KeyNotFoundException。
我想这与我需要以某种方式刷新一些数据有关 - 或者可能使用另一种方法,但不知道如何。
样本:
private void MainWindow_Loaded(object sender, RoutedEventArgs e) {
GraphViewer graphViewer = new GraphViewer();
graphViewer.BindToPanel(Panel);
Graph graph = new Graph();
graph.AddEdge("A", "B");
graphViewer.MouseUp += (s, ev) =>
{
if (graphViewer.ObjectUnderMouseCursor != null)
{
graph.AddEdge("A", "C"); // BOOM!
}
};
graph.Attr.LayerDirection = LayerDirection.LR;
graphViewer.Graph = graph;
}
Run Code Online (Sandbox Code Playgroud)
异常详细信息:
System.Collections.Generic.KeyNotFoundException was unhandled
HResult=-2146232969
Message=The given key was not present in the dictionary.
Source=mscorlib
StackTrace:
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Microsoft.Msagl.WpfGraphControl.GraphViewer.<CreateVNode>b__1d(Edge e) in c:\Users\br\Desktop\MSAGL\automatic-graph-layout-master\GraphLayout\tools\WpfGraphControl\GraphViewer.cs:line 1263
at Microsoft.Msagl.WpfGraphControl.VNode.<get_OutEdges>b__10(Edge e) in …Run Code Online (Sandbox Code Playgroud)