Different kinds of Nodes
Hi,
I'm currently developing a UWP application that uses the Diagram Component.
In my model i have these different clasess :
GenericComponent (ParentClass) (CommonProperty1,CommonProperty2, CommonNode)
- ComponentA (PropertyA,PropertyB,PropertyC) [ShapeStyle1]
- ComponentB (PropertyD,PropertyF,PropertyD) [ShapeStyle2]
- ComponentC (....PropertyM) [ShapeStyle3]
Each of those classes should be represented for a Rectangle Shape in the diagram and a different content template for each one.
After that i want to create an ObservableCollection<GenericComponent> where i can have different objects from this different classess.
Each time i execute componentsCollection.Add(new ComponentA()) => This should create a Object inside the collection and also add it's node to the diagram (the node is the visual representation of the object).
Right now i have two ObservableCollections, everytime i add a component it will loop the collection and add each node to the second collection. This is not the right way to do it and also is not working i get An item with the same key has already been added
What could be the best approach to achieve this?
Thanks
I'm currently developing a UWP application that uses the Diagram Component.
In my model i have these different clasess :
GenericComponent (ParentClass) (CommonProperty1,CommonProperty2, CommonNode)
- ComponentA (PropertyA,PropertyB,PropertyC) [ShapeStyle1]
- ComponentB (PropertyD,PropertyF,PropertyD) [ShapeStyle2]
- ComponentC (....PropertyM) [ShapeStyle3]
Each of those classes should be represented for a Rectangle Shape in the diagram and a different content template for each one.
After that i want to create an ObservableCollection<GenericComponent> where i can have different objects from this different classess.
Each time i execute componentsCollection.Add(new ComponentA()) => This should create a Object inside the collection and also add it's node to the diagram (the node is the visual representation of the object).
Right now i have two ObservableCollections, everytime i add a component it will loop the collection and add each node to the second collection. This is not the right way to do it and also is not working i get An item with the same key has already been added
What could be the best approach to achieve this?
Thanks
SIGN IN To post a reply.
7 Replies
KR
Keerthivasan Ramamoorthy
Syncfusion Team
February 20, 2018 12:26 PM UTC
Hi Fede,
Please find the responses to your queries as below.
| S.no | Query | Response |
| | In my model i have these different clasess : GenericComponent (ParentClass) (CommonProperty1,CommonProperty2, CommonNode) - ComponentA (PropertyA,PropertyB,PropertyC) [ShapeStyle1] - ComponentB (PropertyD,PropertyF,PropertyD) [ShapeStyle2] - ComponentC (....PropertyM) [ShapeStyle3] Each of those classes should be represented for a Rectangle Shape in the diagram and a different content template for each one. After that i want to create an ObservableCollection<GenericComponent> where i can have different objects from this different classess. Each time i execute componentsCollection.Add(new ComponentA()) => This should create a Object inside the collection and also add it's node to the diagram (the node is the visual representation of the object). | We have prepared a simple sample for your requirement. Please find the sample and screenshot as below. Screenshot: Sample details: We have created 3 classes, GenericComponent derives NodeViewModel. ComponentA and ComponentB derives GenericComponent. We have also added properties in it. We have 2 different data templates for component A and B. By default content is null, we have assigned the content property as Component to itself(self-reference), this will enable binding between template and properties of the component. Following some of the ways you can organize your data structure.
|
| 3 | Right now i have two ObservableCollections, everytime i add a component it will loop the collection and add each node to the second collection. | It is possible to set only one collection to SfDiagram.Nodes. We are not sure how are you using 2 different collection and use it for diagram. Please provide some code snippets or a sample to demonstrate your usage. |
| 4 | This is not the right way to do it and also is not working i get An item with the same key has already been added | The reported issue occurred only if we add the same instance to Nodes or Connectors collection of the Diagram. You should not add duplicate objects for SfDiagram.Node or SfDiagram.Connector. Can you please ensure your side whether the collection having different instance? |
Regards,
Keerthivasan R.
DY
Dylan
February 20, 2018 08:23 PM UTC
I've been able to achieve my previous requests,
I would like to know a few more things...
1) How do you disable the Menu (Rotation,Delete, Connection) when you click the node? I'm referring to => https://www.dropbox.com/s/eu9kg3ymkn939bg/Menu.PNG?dl=0
2) I've been able to create dynamic ports some nodes, for example ComponentA have only an out port, others have an out and in port and others have 4 ports (2 in , 2 out) in the attached file you can see how i did it, do you think is there a better way?
3) When you zoom in the Ports get bigger and when you zoom out the ports get smaller, this should not work like this, is there any way to fix it?
4) As you can see in the attached project i have a button inside the ContentTemplate what is the best way to be able to execute a click? Using findvisualchildren? , ICommand?
5) How do i get the selected item in the diagram? I'm using SelectedItems but i would like to only get one...
6) I would like to Start dragging and creating a connector from the port to another port, however right now i cant create connections from the ports or from the create connector button in the node menu, how i do it?
PROJECT
https://www.dropbox.com/s/nibo7j7ykokx89h/135998_Sample-633443148.rar?dl=0
Thank you so much
I would like to know a few more things...
1) How do you disable the Menu (Rotation,Delete, Connection) when you click the node? I'm referring to => https://www.dropbox.com/s/eu9kg3ymkn939bg/Menu.PNG?dl=0
2) I've been able to create dynamic ports some nodes, for example ComponentA have only an out port, others have an out and in port and others have 4 ports (2 in , 2 out) in the attached file you can see how i did it, do you think is there a better way?
3) When you zoom in the Ports get bigger and when you zoom out the ports get smaller, this should not work like this, is there any way to fix it?
4) As you can see in the attached project i have a button inside the ContentTemplate what is the best way to be able to execute a click? Using findvisualchildren? , ICommand?
5) How do i get the selected item in the diagram? I'm using SelectedItems but i would like to only get one...
6) I would like to Start dragging and creating a connector from the port to another port, however right now i cant create connections from the ports or from the create connector button in the node menu, how i do it?
PROJECT
https://www.dropbox.com/s/nibo7j7ykokx89h/135998_Sample-633443148.rar?dl=0
Thank you so much
KR
Keerthivasan Ramamoorthy
Syncfusion Team
February 21, 2018 12:35 PM UTC
Hi Dylan,
Please find the responses to your queries as below.
| S.no | Query | Response | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1 | How do you disable the Menu (Rotation,Delete, Connection) when you click the node? I'm referring to => | We have an option to enable or disable the Quickcommand for the Node. Please find the code example to disable the QuickCommand for Node and also refer the kb link. Code Example:
Screenshot: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | I've been able to create dynamic ports some nodes, for example ComponentA have only an out port, others have an out and in port and others have 4 ports (2 in , 2 out) in the attached file you can see how i did it, do you think is there a better way? | We have modified the sample to meet your requirement. Please find the sample from the attachment. Code example:
|