0

I have got the latest DGML schema and generated a set of c# classes via xsd.exe but I can't see how to programatically add custom properties to a node.

The XML would look something like:

<?xml version="1.0" encoding="utf-8"?>
<DirectedGraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/vs/2009/dgml">
  <Nodes>
    <Node Id="_85" Label="MyNode" CustomProperty="XXX" />
  </Nodes>
  <Properties>
    <Property Id="CustomProperty" Label="YYY" Group="ZZZ" />
  </Properties>
</DirectedGraph>

How do I add CustomProperty attributes to the Node?

Neil
  • 8,482
  • 2
  • 20
  • 42
  • There is no custom property in a Node. You could give it a Group attribute and then use the same Group in the Property node. – jdweng Mar 11 '19 at 00:40
  • There IS a custom property. If you defined a property, then whatever the value of the `Id` field is, becomes a custom property in the `Node`, as shown in the example above. – Neil Mar 12 '19 at 09:23
  • I will double check – Neil Mar 12 '19 at 09:25
  • I did not see in the schema any way of adding a custom property. It is a complicated schema and could of miss the option or you may be using a different version of the schema then the link you provided. – jdweng Mar 12 '19 at 09:51
  • See sample at msdn. I think CustomProperty should be Category : https://docs.microsoft.com/en-us/visualstudio/modeling/directed-graph-markup-language-dgml-reference?view=vs-2015 – jdweng Mar 12 '19 at 09:57

1 Answers1

0

You can absolutely defined custom properties, but they are "metadata" not something you will see on the graph itself. They contain type information about the property which can affect how the respond to those values. Here's an example. If you select the Link with the custom Priority property the F4 property window will show the metadata about that property.

<DirectedGraph xmlns="http://schemas.microsoft.com/vs/2009/dgml">
  <Nodes>
    <Node Id="Banana" UseManualLocation="True" />
    <Node Id="Test" UseManualLocation="True" />
  </Nodes>
  <Links>
    <Link Source="Test" Target="Banana" Priority="10"/>
    <Link Source="Test" Target="Green" />
  </Links>
  <Properties>
    <Property Id="Bounds" DataType="System.Windows.Rect" />
    <Property Id="UseManualLocation" DataType="System.Boolean" />
    <Property Id="Priority" DataType="System.Double"  
              Label="Poobar" Group="Metrics" 
              Description="A fun new property"/>
  </Properties>
  <Styles>
    <Style TargetType="Link">
      <Setter Property="Weight" Expression="Priority * 3" />
    </Style>
  </Styles>
</DirectedGraph>
Chris
  • 532
  • 3
  • 8
  • Thanks @chris, but this doesn't tell me how to add them via the classes generated from schema, does it? – Neil Jul 29 '19 at 12:50
  • Ah, I assume you are using Microsoft.VisualStudio.GraphModel.dll, in that case see the Graph Metadata information in this spec: https://lovettchris.github.io/posts/GraphModel/ – Chris Jul 31 '19 at 21:25