How to refresh just one node?

Let’s assume that I have a name and a description on my nodes. Somewhere on my application one of those fields changes and I’m subscribed to an event triggered when the change happens.

Now I want to update\refresh the specific node where that field belongs to. I’ve been unable to refresh just that node. How can I do that?

Thx in advance

If your node data class implements the INotifyPropertyChanged interface, and if the “name” and “description” property setters raise the PropertyChanged event, and if you data-bound the TextBlock to the corresponding node data property, it ought to update automatically.

So for example if you are using one of the predefined node data classes, GraphLinksModelNodeData or GraphModelNodeData or TreeModelNodeData, you don’t need to do anything beside the TextBlock.Text data-binding. For each property you define on the node data class, be sure to call RaisePropertyChanged in the property setter only when the property value has actually changed.

But if your node data is a class that does not implement INotifyPropertyChanged, or if the “name” or “description” information is not implemented using properties or if they do not raise the PropertyChanged event, and if you are not data-binding the TextBlock.Text property, then you can do the updating in code.

In this scenario I assume you already have the node data object that you care about – the one with the updated “name” or “description” property. If this is not the case, because you only have the key for the node data, see finding node data given a key.

Once you have the node data, you can find the corresponding Node in the Diagram by calling myDiagram.PartManager.FindNodeForData.

Once you have the Node, you can call node.FindNamedDescendant to find a particular named element in the visual tree. Of course you’ll need to x:Name your TextBlock in the DataTemplate so that this search will be able to find that particular TextBlock.

And once you have the TextBlock, you can just set its Text property.

As you can see, just using data-binding is a lot easier to implement for most situations.

Thanks! Your answer helped me a lot.

I already have a working solution.