msgal null refernce exeption
Im using Msgal to print show a graph thats used in my Program. I'm trying to setup a simple graph for testing but when the line graphViewer.Graph = graph; is called I get the exeption in the picture. The code is on startup of the panel where my graph should be displayed in
public partial class Graph : Page { public Graph() { InitializeComponent(); DockPanel graphViewerPanel = new DockPanel(); Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); graph.AddEdge("A", "B"); graph.AddEdge("B", "C"); graph.AddEdge("A", "C").Attr.Color = Microsoft.Msagl.Drawing.Color.Green; graph.FindNode("A").Attr.FillColor = Microsoft.Msagl.Drawing.Color.Magenta; graph.FindNode("B").Attr.FillColor = Microsoft.Msagl.Drawing.Color.MistyRose; Microsoft.Msagl.Drawing.Node c = graph.FindNode("C"); c.Attr.FillColor = Microsoft.Msagl.Drawing.Color.PaleGreen; c.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; GraphViewer graphViewer = new GraphViewer(); graph.Attr.LayerDirection = LayerDirection.LR; //graph.LayoutAlgorithmSettings.EdgeRoutingSettings.EdgeRoutingMode = EdgeRoutingMode.Rectilinear; var global = (SugiyamaLayoutSettings)graph.LayoutAlgorithmSettings; var local = (SugiyamaLayoutSettings)global.Clone(); local.Transformation = PlaneTransformation.Rotation(Math.PI / 2); graph.LayoutAlgorithmSettings = local;
graphViewer.Graph = graph;
graphViewer.BindToPanel(graphViewerPanel);
Main.Children.Add(graphViewerPanel);
} }
public partial class Graph : Page { public Graph() { InitializeComponent(); DockPanel graphViewerPanel = new DockPanel(); Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); graph.AddEdge("A", "B"); graph.AddEdge("B", "C"); graph.AddEdge("A", "C").Attr.Color = Microsoft.Msagl.Drawing.Color.Green; graph.FindNode("A").Attr.FillColor = Microsoft.Msagl.Drawing.Color.Magenta; graph.FindNode("B").Attr.FillColor = Microsoft.Msagl.Drawing.Color.MistyRose; Microsoft.Msagl.Drawing.Node c = graph.FindNode("C"); c.Attr.FillColor = Microsoft.Msagl.Drawing.Color.PaleGreen; c.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond; GraphViewer graphViewer = new GraphViewer(); graph.Attr.LayerDirection = LayerDirection.LR; //graph.LayoutAlgorithmSettings.EdgeRoutingSettings.EdgeRoutingMode = EdgeRoutingMode.Rectilinear; var global = (SugiyamaLayoutSettings)graph.LayoutAlgorithmSettings; var local = (SugiyamaLayoutSettings)global.Clone(); local.Transformation = PlaneTransformation.Rotation(Math.PI / 2); graph.LayoutAlgorithmSettings = local;
graphViewer.Graph = graph;
graphViewer.BindToPanel(graphViewerPanel);
Main.Children.Add(graphViewerPanel);
} }
0 Replies