private void OnFileOpen(object sender, ExecutedRoutedEventArgs e) { Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog(); ofd.RestoreDirectory = true; ofd.DefaultExt = ".sgx"; ofd.Filter = "GraphXML (.sgx)|*.sgx|All Files|*.*"; if (ofd.ShowDialog() == true) { graphCanvas.Children.Clear(); try { FileName = ofd.FileName; Graph = WebGraph.Logic.GraphXmlSerializer.Deserialize(FileName); Layouter = new WebGraph.Logic.GraphLayouter(Graph); Brush nodeFg = new SolidColorBrush(Properties.Settings.Default.NodeForeground); Brush nodeBg = new SolidColorBrush(Properties.Settings.Default.NodeBackground); Graph.ForAllEdges(edge => { Line line = new Line(); line.Stroke = nodeBg; edge.Tag = line; graphCanvas.Children.Add(line); }); Graph.ForAllNodes(node => { TextBlock text = new TextBlock(); text.Text = node.Label; text.Foreground = nodeFg; text.Background = nodeBg; text.Padding = new Thickness(4, 0, 4, 0); text.FontSize = 12; text.MouseLeftButtonDown += new MouseButtonEventHandler(OnNodeMouseLeftButtonDown); node.Tag = text; graphCanvas.Children.Add(text); }); } catch (Exception exc) { OnFileNew(this, null); // force a complete reset MessageBox.Show(exc.Message, exc.GetType().FullName); } graphCanvas.UpdateLayout(); Graph.ForAllNodes(new WebGraph.Logic.NodeCallback(CenterNodes)); Graph.ForAllNodes(new WebGraph.Logic.NodeCallback(UpdateNodeSize)); Layouter.ResetDamper(); } }