public class NodeAddInfo {
public string ParentID;
public string Content;
}
public List<NodeAddInfo> AddInfo = new List<NodeAddInfo>()
{
new NodeAddInfo(){ Content = "NodeContent", ParentID = "diagram" }
};
DiagramNode node1 = new DiagramNode()
{
// Position of the node
OffsetX = 250,
OffsetY = 250,
// Size of the node
Width = 100,
Height = 100,
Style = new NodeShapeStyle() { Fill = "#6BA5D7", StrokeColor = "white" },
AddInfo = AddInfo
};
But now when I try and read the selected node and read in its AddInfo attribute. Seeing that it is in Object form I do an explicit parse to List<NodeAddInfo>. It then throws an error for some reason.
1. List<NodeAddInfo> addinfo = (List<NodeAddInfo>) SourceNode.AddInfo;Please let me know if you guys have any suggestions or sample code. It could be to do with the fact that I load my nodes into the pallet and then drag them from there onto the diagram area. Whereas with the example they load the node directly to the diagram area.
Dictionary<string, object> data = new Dictionary<string, object>();
data.Add("Mass", 15);
data.Add("Pressure", 50);
data.Add("Velocity", 30);
new DiagramNode(){
Id="node1",
Height = 100,
Width = 100,
OffsetX = 500,
AddInfo = data,
OffsetY = 100
},
public void SelectionChanged(IBlazorSelectionChangeEventArgs args)
{
if(args.State == EventState.Changed && args.Type == ChangeType.Addition && args.NewValue.Nodes.Count > 0)
{
if (args.NewValue.Nodes[0].AddInfo != null)
{
Dictionary<string, object> addInfoData = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(args.NewValue.Nodes[0].AddInfo.ToString());
StateHasChanged();
}
}
} |
<SfDiagram ID="diagram" Width="1000px" Height="@Height" @ref="@diagram" Nodes="@NodeCollection" Connectors="@ConnectorCollection">
<DiagramEvents SelectionChanged="@SelectionChanged" MouseEnter="@MouseEnter"></DiagramEvents>
</SfDiagram>
public void SelectionChanged(IBlazorSelectionChangeEventArgs args)
{
if(args.State == EventState.Changed && args.Type == ChangeType.Addition && args.NewValue.Nodes.Count > 0)
{
if (args.NewValue.Nodes[0].AddInfo != null)
{
Dictionary<string, object> addInfoData = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(args.NewValue.Nodes[0].AddInfo.ToString());
StateHasChanged();
}
}
} |