update graph at runtime

Jul 3, 2012 at 7:55 AM

hello, I would like to know how I could update the graph, changing any value. 
in the example that you give if I change a name at runtime, and may update the graph?. 
Thank you.

Coordinator
Jul 6, 2012 at 11:32 AM

Hello,

I will explain that on the example (using the latest revision from VCS). Let's say that we want to change the behaviour of the "Add new person" button so that instead of adding a new person into the graph, it changes the name of the first person (first vertex). 

1) change the Person class: implement IPropertyNotifyChanged

    public class Person : INotifyPropertyChanged
    {
    	private string name;
    	public string Name
    	{
    		get { return this.name; }
    		set
    		{
    			this.name = value;
    			if (this.PropertyChanged != null) {
    				this.PropertyChanged(this, new PropertyChangedEventArgs("Name"));
    			}
    		}
    	}

2) change the code of the MainWindowViewModel.CreatePerson mehtod accordingly:

        public void CreatePerson()
        {
            if (this.PersonNames.Any(x => x == this.NewPersonName))
            {
                // such a person already exists: there should be some validation message, but 
                // it is not so important in a demo
                return;
            }

            this.Graph.Vertices.First().Name = this.NewPersonName;
        }
        

Now when you enter a name into the "new person's name" text box and depress the "Add new person" button, it will not add a new person, but it will change the name of the first person (i.e. first vertex in the this.Graph.Vertices collection).

Hope that helps