Get isSelected value

1

This is parts of link template.

i want to get link’s isSelected value in binding function…

because i’m implemente WPF multi binding.

There are no multibindings in GoJS. You’ll have to make do with multiple Bindings, or with a less efficient general binding. The important point is that there is a second argument to the binding conversion function, which gives you a reference to the GraphObject whose property is data bound.

It isn’t clear to me what you want to do, so I’ll make something up. Please examine this code and try it out. The visibility of the second TextBlock is dependent on either the Node being selected or on the data.show property being true. Click on the “Test” button to toggle the value of that data.show property, which you can see reflected in the Model.toJson result.

<!DOCTYPE html>
<html>
<head>
  <title>Minimal GoJS Sample</title>
  <!-- Copyright 1998-2020 by Northwoods Software Corporation. -->

  <script src="go.js"></script>
  <script id="code">
  function init() {
    var $ = go.GraphObject.make;

    myDiagram =
      $(go.Diagram, "myDiagramDiv",
        {
          "undoManager.isEnabled": true,
          "ModelChanged": function(e) {     // just for demonstration purposes,
            if (e.isTransactionFinished) {  // show the model data in the page's TextArea
              document.getElementById("mySavedModel").textContent = e.model.toJson();
            }
          }
        });

    myDiagram.nodeTemplate =
      $(go.Node, "Auto",
        $(go.Shape,
          { fill: "white", portId: "", fromLinkable: true, toLinkable: true, cursor: "pointer" },
          new go.Binding("fill", "color")),
        $(go.Panel, "Vertical",
          { margin: 8 },
          $(go.TextBlock,
            { editable: true },
            new go.Binding("text").makeTwoWay()),
          $(go.TextBlock, "comment",
            { visible: false, editable: true, font: "italic 10pt sans-serif" },
            new go.Binding("text", "text2").makeTwoWay(),
            new go.Binding("visible", "isSelected", function(sel, tb) { return sel || tb.part.data.show || false; }).ofObject(),
            new go.Binding("visible", "show", function(show, tb) { return show || tb.part.isSelected; })
          )
        )
      );

    myDiagram.model = new go.GraphLinksModel(
    [
      { key: 1, text: "Alpha", color: "lightblue" },
      { key: 2, text: "Beta", color: "orange" }
    ],
    [
      { from: 1, to: 2 }
    ]);
  }

  function test() {
    var node = myDiagram.selection.first();
    if (node instanceof go.Node) {
      myDiagram.model.commit(function(m) {
        m.set(node.data, "show", !node.data.show);
      });
    }
  }
  </script>
</head>
<body onload="init()">
  <div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:600px"></div>
  <button onclick="test()">Test</button>
  <textarea id="mySavedModel" style="width:100%;height:250px"></textarea>
</body>
</html>