title: Can't draw in wpf using graphsharp unless I call the method before the InitializeComponent method
body: <p>I followed the video tutorial on <a href="http://graphsharp.com" rel="nofollow">http://graphsharp.com</a> on how to use graph# library with WPF, and it was quite easy to locate some vertices and the edges joining them. The code of this graph was written in a method which was called in the <code>MainWindow</code> method before the <code>InitializeComponent</code> method, and thus when compiling, the graph appears automatically.
  The problem is that I tried to call the same method of drawing in the <code>button_click</code> method, but nothing appears each time I click the button.</p>
  
  <p>Here's my code</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      private IBidirectionalGraph&lt;object, IEdge&lt;object&gt;&gt; _graphToVisualize;
  
      public IBidirectionalGraph&lt;object, IEdge&lt;object&gt;&gt; GraphToVisualize
      {
          get { return _graphToVisualize; }
      }
  
      public MainWindow()
      {
          //CreateGraphToVisualize();     //When compiling with this instruction uncommented, the graph is drawn
          InitializeComponent();
      }
  
      private void CreateGraphToVisualize()
      {
          var g = new BidirectionalGraph&lt;object, IEdge&lt;object&gt;&gt;();
  
          // add the vertices to the graph
          string[] vertices = new string[5];
          for (int i = 0; i &lt; 5; i++)
          {
              vertices[i] = i.ToString();
              g.AddVertex(vertices[i]);
          }
  
          // add edges to the graph
          g.AddEdge(new Edge&lt;object&gt;(vertices[0], vertices[1]));
          g.AddEdge(new Edge&lt;object&gt;(vertices[1], vertices[2]));
          g.AddEdge(new Edge&lt;object&gt;(vertices[2], vertices[3]));
          g.AddEdge(new Edge&lt;object&gt;(vertices[3], vertices[1]));
          g.AddEdge(new Edge&lt;object&gt;(vertices[1], vertices[4]));
  
  
  
          _graphToVisualize = g;
      }
  
      private void button1_Click(object sender, RoutedEventArgs e)
      {
          CreateGraphToVisualize();
      }
  }
  </code></pre>
  
  <p>}</p>