Binding UI info of Unbound Node

I have a requirement that I have to show some information of selected link on the diagram. I was able to achieve the same by adding the node object in the .cs file. This node takes a label as child and the label’s content has the information of the selected medium.

There could me multiple of these nodes in the diagram as there could me multiple links in the diagram.
I am able to achieve the same by adding node from the code.

What I want to achieve is that the unbound node’s template should be xaml and this node to be added to PartsModel programatically ( i.e. in C# code ). Also the label’s content should be updatable via view model.

Is it possible achieve the same? What is your suggestion on this ?

I would add the data to the model and use different categories resulting in using different templates.

I was able to get the above functionality by sending the UserControl to Content property of the Node object.

Ah, OK. Yes, if you are constructing the UserControl programmatically, that should work. Otherwise, you could set the Node.ContentTemplate to the DataTemplate that you want to use.

Hi Walter,

As per your suggestion I tried setting the datatemplate. Still I face the same issue. The node is shown only after I zoom in or out.
This is the code I tried.

        var dt = new FrameworkElementFactory(typeof(TextBox));
        dt.SetValue(TextBox.TextProperty, "Test");
        ubNode.ContentTemplate = new DataTemplate() { VisualTree = dt}; 

Just for testing I used TextBlock instead of my usercontrol

I was able to replicate the same issue even with your suggestion. I just deleted the code under Save button and added the following for Piping example.

        Node node = new Node();
        node.Location = new Point(100, 100);
        node.Content = new TextBox() {Text = "Sample"};

        if(myDiagram.PartsModel != null)
            myDiagram.PartsModel.AddNode(node);
        else
        {
            myDiagram.InitialParts.Add(node);
        }

Once I click on save button I have zoom in/out to see the node on the diagram.
The issue still persists even though we used ContentTemplate. Following code

        Node node = new Node();
        node.Location = new Point(100, 100);
        var dt = new FrameworkElementFactory(typeof(TextBox));
        dt.SetValue(TextBox.TextProperty, "Test");
        node.ContentTemplate = new DataTemplate() { VisualTree = dt};

        if(myDiagram.PartsModel != null)
            myDiagram.PartsModel.AddNode(node);
        else
        {
            myDiagram.InitialParts.Add(node);
        }

I just added myDiagram.PartsModel.StartTransaction(“Unbound node”);
and myDiagram.PartsModel.CommitTransaction(“Unbound node”);

the node started coming up in the UI without doing any zoom in/out but the location still goes to left top corner. The location issue still exists.

If you look at that node’s Location, what value does it have? I bet it’s still at (100,100) unless the Diagram.Layout has moved it.

Hi Walter,

Thanks for the inputs. I just setting the location outside of the constructor of Node and it worked.
Also I am using the Content property of the Node which gets a UserControl object and its working fine !!