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

Connection's target is null

2 Answers 66 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Paweł
Top achievements
Rank 1
Paweł asked on 07 Feb 2013, 11:41 AM
Hi,

I decided to ask here, because after few days I still have no idea how the RadDiagram works.
Here is my code (it's not the whole file, just the most important - in my opinion - parts):

public class OrgGraphSource : ObservableGraphSourceBase<CMSHierarchicalParticipantCMSHierarchicalParticipantLink>
{
	
	public void Populate(CMSOrgStructure orgStructure)
        {
            if (orgStructure == null)
                return;
            
            foreach (var item in orgStructure.Participants) 
                base.AddNode(item);                

	    foreach(var link in orgStructure.ParticipantLinks)
		base.AddLink(link);
 
        }

	public override void AddNode(CMSHierarchicalParticipant participant)
        {
            _commandingProvider.AddParticipantToOrgStructure(_ownerId_authorIdServiceConverter.Convert(participant));
            base.AddNode(participant);
            participant.PropertyChanged += Node_PropertyChanged;
        }
	public override bool RemoveItem(CMSHierarchicalParticipant participant)
        {
            participant.PropertyChanged -= Node_PropertyChanged;
 
            bool itemRemoved = base.RemoveItem(participant);
 
            if (itemRemoved)
            {                
                _commandingProvider.RemoveParticipantFromOrgStructure(_ownerId_authorIdServiceConverter.Convert(participant));
            }
 
            return itemRemoved;
        }

	public override void AddLink(CMSHierarchicalParticipantLink link)
        {
            link.PropertyChanged += link_PropertyChanged;
            base.AddLink(link);
        }
 
        void link_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            var link = sender as CMSHierarchicalParticipantLink;
            if (link == null || link.Source == null || link.Target == null)
                return;
 
            _commandingProvider.AddLinkInOrgStructure(_ownerId_authorIdServiceConverter.Convert(sender as CMSHierarchicalParticipantLink));
        }
}

The class above is my GraphSource that is bounded to RadDiagram in xaml. As you can see, I tried to attach handler to link.PropertyChanged event and it worked for a moment, but now I did something wrong, I think. Anyway - when I create link on diagram, the AddLink is invoked for the first time. Target is null, but Source is valid object that connection's going from. When I attach the connection to the destination object, AddLink method is called again, but this time also Target is null, and Source is a object that connection is going to. All of this is very strange and I cannot understand how to work with the connections. As you can see, I need to save each user's action in database (using _commandingProvider), so I need to know when new valid connection is set (valid => if connecting two objects).


I can also show xaml:
<telerik:RadDiagram x:Name="OrgChart"
                            Grid.Column="2"
                            IsEnabled="{Binding IsEnabled}"
                            GraphSource="{Binding GraphSource}"
                            SelectedItem="{Binding SelectedPerson, Mode=TwoWay}"
                            ScrollViewer.HorizontalScrollBarVisibility="Visible"
                            ScrollViewer.VerticalScrollBarVisibility="Visible"
                            IsConnectorsManipulationEnabled="True"
                            IsManipulationAdornerVisible="True" 
                            ShapeStyle="{StaticResource DiagramNodeStyle}"
                            ConnectionStyle="{StaticResource DiagramEdgeStyle}" />

And of course CMSHierarchicalParticipantLink implements ILink<CMSHierarchicalParticipant>...

I would appreciate any help you can provide me with, thank you in advance.
Paweł

2 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 12 Feb 2013, 02:24 PM
Hi Pawel,

 Similar issues are discussed in this forum thread. Could you please take a look at it and let us know if it helps you. One possible solution is to use the ConnectionManipulationCompleted event and the other approach is to use the Setter of the Target in the VeiwModel.

All the best,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Paweł
Top achievements
Rank 1
answered on 13 Feb 2013, 07:38 AM
Hello Petar,

To be honest, I investigated the issue a bit more and found the source of my problem. It was something that was preventing PropertyChanged event from being fired up. In other words - it was not related with the Diagram itself. Now, when PropertyChanged event can be fired properly, link_PropertyChanged method is invoked, I check whether property name is "Target" and do necessary job then.

Thanks for help,
Best regards
Paweł
Tags
Diagram
Asked by
Paweł
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Paweł
Top achievements
Rank 1
Share this question
or