DataBinding and Click and Drag Connection

2 posts, 0 answers
  1. David
    David avatar
    5 posts
    Member since:
    Jun 2013

    Posted 28 Aug 2013 Link to this post

    Hi

    I'm trying to implement a diagram control using databinding. But I'm unable to use creating connections by click on one of the shape's port and drag it to another shape's port like the examples in the WPF demo. I've tried to set "IsConnectorManipulationEnabled" to true that doesn;t work either. I've attached my GraphSourceBase code below. Any suggestions to enable the default connector behaviour in databinding method ?

    public class CMGraphSource : GraphSourceBase<CMDeviceShapeViewModel, ILink>
    {
     
        public CMGraphSource()
        {
            //Load initial objects into CMDiagram (Reciever and USBTripods)
            int TripodCount = ConnectionHandler.Instance.getUSBTripodCount();
     
            for (int i = 0; i < TripodCount; i++)
            {
                Tripod t = ConnectionHandler.Instance.getUSBTripod(i);
                AddItem(new TripodCMViewModel(t.id));
            }
     
            int RecieverCount = ConnectionHandler.Instance.getRecieverCount();
     
            for (int i = 0; i < RecieverCount; i++)
            {
                Reciever r = ConnectionHandler.Instance.getReciever(i);
                AddItem(new RecieverCMViewModel(r.id));
            }
     
            ConnectionHandler.Instance.PropertyChanged += onConnectionHandlerDeviceChange;
        }
     
        private void onConnectionHandlerDeviceChange(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName.Equals("AddReciever", StringComparison.InvariantCultureIgnoreCase))
            {
                Reciever r = (Reciever)sender;
                AddItem(new RecieverCMViewModel(r.id));
            }
            else if (e.PropertyName.Equals("RemoveReciever", StringComparison.InvariantCultureIgnoreCase))
            {
                Reciever r = (Reciever)sender;
     
            }
            else if (e.PropertyName.Equals("AddUSBTripod", StringComparison.InvariantCultureIgnoreCase))
            {
                Tripod t = (Tripod)sender;
                AddItem(new TripodCMViewModel(t.id));
            }
            else if (e.PropertyName.Equals("RemoveUSBTripod", StringComparison.InvariantCultureIgnoreCase))
            {
                Tripod t = (Tripod)sender;
            }
        }
     
        public void AddItem(CMDeviceShapeViewModel model)
        {
            if (base.InternalItems.Contains(model))
                return;
     
            base.AddNode(model);
     
        }
     
    }
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 29 Aug 2013 Link to this post

    Hi David,

    When you need to create connections interactively in MVVM scenarios this means that you need to support 2-way binding between your View and your ViewModel. The RadDiagram supports bi-directional MVVM scenarios with the following collections: ObservableGraphSourceBase and SerializableGraphSourceBase. You can check out this help articles providing more information on this topic.

    Diagram DataBinding (Section 2-way MVVM)
    How To Serialize a DataBound Diagram
    XAML GitHub Diagram MVVM Sample

    Regards,
    Petar Mladenov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top