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

How to prevent connections manipulation.

1 Answer 125 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Maxim
Top achievements
Rank 1
Maxim asked on 17 Jan 2018, 01:58 PM
How to prevent attach connection to shape, detach connection from shape and delete connection from diagram? I want to make decision on ObservableGraphSourceBase level.

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 19 Jan 2018, 03:41 PM
Hi Maxim,

To be honest the connection manipulation is not well suited for MVVM. The best way to handle it is via ConnectionManiopulation events.

For GraphSource handling of connection creating, removing and inserting in graphsource you can override the following methods of GraphSoureBase:
public override void AddLink(Link link)
       {
           base.AddLink(link);
       }
 
       public override ILink CreateLink(object source, object target)
       {
           return base.CreateLink(source, target);
       }
 
       public override bool RemoveLink(Link link)
       {
           return base.RemoveLink(link);
       }

When you set Source or Target (which can also be set internally, in Diagram's core code), the OnPropertyChanged of the LinkViewModelBase will be fired, so you can try some code like:
public class Link : LinkViewModelBase<NodeViewModelBase>
    {
        protected override void OnPropertyChanged(string propertyName)
        {
            if (propertyName == "Target" && this.Target != null)
            {
                // your custom logic here
                this.Target = null;
            }
            base.OnPropertyChanged(propertyName);
        }

I hope this will help you move forward.

Regards,
Petar Mladenov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
Diagram
Asked by
Maxim
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or