public DiagramVM() { LoadCommand = new Command(OnLoad); SaveCommand = new Command(OnSave); // Need to add new class which are not derived from our ViewModel classess // Need to add new types KnownTypes = () => new List <Type>() { typeof(NodeContent) }; CustomNode node1 = new CustomNode() { OffsetX = 150, OffsetY = 150, UnitHeight = 100, UnitWidth = 100, CustomContent = new NodeContent() { Content = "Node1" }, Content = new NodeContent() { Content = "Node1" }, CustomContentTemplate = "NodeTemplate", ContentTemplate = App.Current.Resources["NodeTemplate"] as DataTemplate, }; (Nodes as NodeCollection).Add(node1); CustomNode node2 = new CustomNode() { OffsetX = 300, OffsetY = 300, UnitHeight = 100, UnitWidth = 100, CustomContent = new NodeContent() { Content = "Node2" }, Content = new NodeContent() { Content = "Node2" }, CustomContentTemplate = "NodeTemplate", ContentTemplate = App.Current.Resources["NodeTemplate"] as DataTemplate, }; (Nodes as NodeCollection).Add(node2); ConnectorViewModel Con = new ConnectorViewModel() { SourceNode = node1, TargetNode = node2, }; (Connectors as ConnectorCollection).Add(Con); }
public DiagramVM() { // Initialize ItemAdded command to add the content for loaded node ItemAddedCommand = new Command(OnItemAdded); LoadCommand = new Command(OnLoad); SaveCommand = new Command(OnSave); // Need to add new class which are not derived from our ViewModel classess // Need to add new types KnownTypes = () => new List <Type>() { typeof(NodeContent) }; CustomNode node1 = new CustomNode() { OffsetX = 150, OffsetY = 150, UnitHeight = 100, UnitWidth = 100, ShapeStyle = App.Current.Resources["NodeStyle"] as Style, Shape = App.Current.Resources["Rectangle"], CustomShape = "Rectangle", CustomContent = new NodeContent() { Content = "Node1" }, CustomStyle = "NodeStyle", Content = new NodeContent() { Content = "Node1" }, }; (Nodes as NodeCollection).Add(node1); CustomNode node2 = new CustomNode() { OffsetX = 300, OffsetY = 300, UnitHeight = 100, UnitWidth = 100, ShapeStyle = App.Current.Resources["NodeStyle"] as Style, Shape = App.Current.Resources["Ellipse"], CustomShape = "Ellipse", CustomContent = new NodeContent() { Content = "Node2" }, CustomStyle = "NodeStyle", Content = new NodeContent() { Content = "Node2" }, }; (Nodes as NodeCollection).Add(node2); ConnectorViewModel Con = new ConnectorViewModel() { SourceNode = node1, TargetNode = node2, }; (Connectors as ConnectorCollection).Add(Con); }