Not able to position the nodes when using ItemsSource to bind the nodes

When i bind an observablecollection of nodes to DiagramModel though i specify the X and Y positon of the nodes, they always appear at (0,0) position.
XAML



CODE BEHIND
public partial class EditorDiagramView : ViewBase
{
public EditorDiagramView()
{
InitializeComponent();
//this.DataContext = new EditorDiagramViewModel();
AddNodes();
}

private void AddNodes()
{
Node _diagramNode = null;
for (int i = 0; i < 3; i++)
{
_diagramNode = new Node();
_diagramNode.Content = "Node1";
_diagramNode.OffsetX = 1 + i * 100;
_diagramNode.OffsetY = 1 + i * 100;
DiagramNodes.Add(_diagramNode);
}
}

private Node _diagramNode;
private ObservableCollection _diagramNodes = new ObservableCollection();

public ObservableCollection DiagramNodes
{
get { return _diagramNodes; }
}
------------
Can you please let me know what is wrong here.
When instead of binding to ItemsSource if I add the Nodes individually the position of the Nodes take effect.

Please suggest a solution to this.



1 Reply

RT Ramya Thirugnanam Syncfusion Team November 24, 2011 03:36 AM UTC

Hi Satish,
With regards to Not able to position the nodes when using ItemSource on DiagramModel, we have created a sample to address your query. Please refer to the attachment .

Details:

After analyzing your code snippet, we can see that you are using ItemSource to DiagramModel as observablecollection of Node. This creates the reported problem.
Steps to achieve:
1. ItemSource to DiagramModel must contain a collection of Node’s content (UIElement, Business Object), but not collection of Node.
2. OffsetX and OffsetY are dependency property that can be bounded to Offset property of Node’s Content.
3. The DataTemplate of the Node content can be specified using ContentTemplate property of the Node.
We have achieved your requirement using the above steps.

Please let us know if you have any concerns.
Regards,
Ramya




ManualLayoutDiagram_d79f44a.zip

Loader.
Up arrow icon