Linkable

Hi,

I’ve nearly got to grips with the programming model, but occasionally get stuck and, after spending my day trying to resolve this myself, I have to give up and ask …

Part of the graph tool that I am building requires that, if a node has any connected links, then it cannot be dropped onto a Group node. This only applies to Group nodes that are not linkableTo or LinkableFrom.

I have a number of different templates that I use for the Groups, the one below defines that it is neither linkable to or from.

        <DataTemplate x:Name="PrioritizeTemplate">
            <go:NodePanel Style="{StaticResource SpotPanelStyle}" 
						  go:Node.LinkableFrom="False"
						  go:Node.LinkableTo="False"
						  go:Part.DropOntoBehavior="AddsToGroup"
					>
                    <TextBlock
						HorizontalAlignment="Left"
						VerticalAlignment="Top"
						Style="{StaticResource TextBlockStyle}" 
						Text="{Binding Data.Text, Mode=OneWay}" Foreground="White" />
            </go:NodePanel>
        </DataTemplate>

When I run this code, the diagram edit honours the LinkableFrom and LinkableTo conditions, but what I need to do is, before I allow a node to be dropped onto it (I have a custom DraggingTool) - I want to check that evaluate the LinkableFrom/To properties on the Group node.

I have used the static methods on the Group/Node classes, but they always return null…

            var top = this.Diagram.Panel.FindElementsAt<Group>(pt,
                                                                 Part.FindAncestor<Group>,
                                                                 px => !Diagram.SelectedParts.Contains(px),
                                                                 SearchLayers.Parts).FirstOrDefault();
 
            var linkableFrom = Group.GetLinkableFrom(top);
            var linkableTo = Group.GetLinkableTo(top);
 

The above code is called during a ConsiderDragOver method. The “top” returns the Group that I am expecting - but the GetLinkableFrom/To always returns a null.

I know that it’s going to something obvious, but can’t get to the bottom of it.

On another note … How do I enable the whole surface area of the Group node to be LinkStart’able and LinkEnd’able ?

I have resolved the issue of making the whole Group area to be LinkStartable/Endable …

I had modified the LinkingTool so that it only starts when the Ctrl key is pressed - but this also has the effect of altering the logic that enables the link to be dropped anywhere on the Group’s surface.

Which override method is your code in?
It’s normal to override DraggingTool.IsValidMember in order to decide whether add a particular Node is acceptable to a Group.
Using that method would mean you don’t have to search for the Group that it’s over.
I’m wondering if maybe you’re getting a different Group.

BTW, it’s a bit odd to be adding nodes to groups that don’t use a GroupPanel or at least some good sized Panels. It means that the added nodes won’t be visually “within” the group.

EDIT: oops – crossing messages…

Thanks for the speed response.

Thanks, I willl use the IsValidMember method override. Your program model is so extensible, it’s sometimes difficult to identify the correct override!

I have implemented a new Layout and DragDrop scheme, which allows a node to be reordered within a Group box. The layout scheme is basically an implementation of the GridLayout - but has extensions to enable the contained children to be reorganised by dragging the contained node to the new location within the Group.

I’m not entirely sure if I am re-inventing the wheel - but it works - that is - only if I use a NodePanel. If I use a GroupPanel, there are side effects (related to child positioning) - that I could not code around.

I’m quite happy with what I’ve developed - but am now stuck on the part where I need to progmattically identify if a node/group can accept links to/from. I’m sure that I’m doing it correctly, but I’m obviously missing something!

Sorted it ...

Confusion over FrameworkElements …

To access the DependencyProperties I should have been using the VisualElement - not the Node/Group object.