This is a migrated thread and some comments may be shown as answers.

DataBinding and Click and Drag Connection

1 Answer 76 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 29 Aug 2013, 02:47 AM
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);
 
    }
 
}

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 29 Aug 2013, 07:02 AM
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 >>
Tags
Diagram
Asked by
David
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or