Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7780723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:59:35+00:00 2026-06-01T18:59:35+00:00

I followed the video tutorial on http://graphsharp.com on how to use graph# library with

  • 0

I followed the video tutorial on http://graphsharp.com 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 MainWindow method before the InitializeComponent method, and thus when compiling, the graph appears automatically.
The problem is that I tried to call the same method of drawing in the button_click method, but nothing appears each time I click the button.

Here’s my code

public partial class MainWindow : Window
{
    private IBidirectionalGraph<object, IEdge<object>> _graphToVisualize;

    public IBidirectionalGraph<object, IEdge<object>> 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<object, IEdge<object>>();

        // add the vertices to the graph
        string[] vertices = new string[5];
        for (int i = 0; i < 5; i++)
        {
            vertices[i] = i.ToString();
            g.AddVertex(vertices[i]);
        }

        // add edges to the graph
        g.AddEdge(new Edge<object>(vertices[0], vertices[1]));
        g.AddEdge(new Edge<object>(vertices[1], vertices[2]));
        g.AddEdge(new Edge<object>(vertices[2], vertices[3]));
        g.AddEdge(new Edge<object>(vertices[3], vertices[1]));
        g.AddEdge(new Edge<object>(vertices[1], vertices[4]));



        _graphToVisualize = g;
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        CreateGraphToVisualize();
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:59:37+00:00Added an answer on June 1, 2026 at 6:59 pm

    your problem is, that the window use a binding to the graphvisualize

    <Window x:Class="MainWindow "
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
            xmlns:zoom="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions"
            Title="Window1" Height="300" Width="300" x:Name="root">
      <Grid>
        <zoom:ZoomControl>
          <graphsharp:GraphLayout x:Name="graphLayout"
                                  Graph="{Binding ElementName=root,Path=GraphToVisualize}"
                                  LayoutAlgorithmType="FR" OverlapRemovalAlgorithmType="FSA"
                                  HighlightAlgorithmType="Simple" />
        </zoom:ZoomControl>
      </Grid>
    </Window>
    

    use a dependency property or use INotifyPropertyChanged interface to solve your problem

    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        private IBidirectionalGraph<object, IEdge<object>> _graphToVisualize;
    
        public IBidirectionalGraph<object, IEdge<object>> GraphToVisualize {
          get { return this._graphToVisualize; }
          set {
            if (!Equals(value, this._graphToVisualize)) {
              this._graphToVisualize = value;
              this.RaisePropChanged("GraphToVisualize");
            }
          }
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        public void RaisePropChanged(string name) {
          var eh = this.PropertyChanged;
          if (eh != null) {
            eh(this, new PropertyChangedEventArgs(name));
          }
        }
    
        private void CreateGraphToVisualize()
        {
            var g = new BidirectionalGraph<object, IEdge<object>>();
    
            // add the vertices to the graph
            string[] vertices = new string[5];
            for (int i = 0; i < 5; i++)
            {
                vertices[i] = i.ToString();
                g.AddVertex(vertices[i]);
            }
    
            // add edges to the graph
            g.AddEdge(new Edge<object>(vertices[0], vertices[1]));
            g.AddEdge(new Edge<object>(vertices[1], vertices[2]));
            g.AddEdge(new Edge<object>(vertices[2], vertices[3]));
            g.AddEdge(new Edge<object>(vertices[3], vertices[1]));
            g.AddEdge(new Edge<object>(vertices[1], vertices[4]));
    
            GraphToVisualize = g;
        }
    }
    

    hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a new facebook application deverloper. I followed this tutorial: http://www.adobe.com/devnet/facebook/articles/video_facebook_quick_start.html but I
I followed this tutorial: https://github.com/EllisLab/CodeIgniter/wiki/PDF-generation-using-dompdf However, I can't seem to set the path right.
I'm trying to use ksoap to call a simple webservice. I followed this video
I followed this code project tutorial for using SharpGL with WPF to create a
I followed this video tutorial but i am stuck.When i click on the login
Followed http://damieng.com/blog/2010/04/26/creating-rss-feeds-in-asp-net-mvc to create RSS for my blog. Everything fine except html tags in
I followed this tutorial , and included a video player in my app. But
I followed the following tutorial to help me create a datagrid ( http://www.asp.net/web-pages/videos/aspnet-razor-pages/displaying-data-in-a-grid ),
Here are the steps I've followed - pretty much this: http://www.youtube.com/watch?v=cFNtD098Bbk&feature=player_embedded Create new Tab
Possible Duplicate: Database Deployment issues I followed the steps in this video: http://www.asp.net/iis/videos/developing-and-deploying-in-a-shared-hosting I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.