Hi I would like to know the location of DiagramNode when Node dropped on to the xamdiagram control, I am currently using Item_Added event to capture the DiagrameNode type, but It's Location (X-Axis, Y-Axis) is always set to 0, 0
Hello Manoj,
I have been looking into your enquiry and this behavior is expected since the event is fired as soon as an item is added to the collection and before its properties are set. What you can do to get the position you want is either use a dispatcher like so:
private void diagram_ItemAdded(object sender, DiagramItemAddedEventArgs e)
{
Dispatcher.BeginInvoke(new Action(() =>
Debug.WriteLine((e.Item as DiagramNode).Position);
}), System.Windows.Threading.DispatcherPriority.Background, null);
}
or wait for the position property to be updated like so:
(e.Item as DiagramNode).PropertyChanged += node_PropertyChanged;
void node_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
if (e.PropertyName == "Position")
Debug.WriteLine("Position changed: " + (sender as DiagramNode).Position);
(sender as DiagramNode).PropertyChanged -= node_PropertyChanged;
Please let me know, if I can be of any further assistance on the matter.
I exactly did that, I need to know if there is better way :)
I am still following your thread. I am just checking the progress of this issue and if you need any more assistance.
If you would like to get the nodes position when an item is added to the diagram, I would suggest you to follow one of the approaches Petar has shared since accessing the position in the Item_Added event directly after the node was added would result in a default (0,0) coordinates.