Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
305
Xamdiagram Node Location
posted

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

Parents
No Data
Reply
  • 27093
    posted

    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:

     

    private void diagram_ItemAdded(object sender, DiagramItemAddedEventArgs e)
        (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.

Children