Node overlapping

I have an issu with my nodes :

As you can see, I can drag my node over an other. I can’t do it entirely but I can until my node center…

In my custom dragging tool, I have :

Part overpart = this.Diagram.Panel.FindElementsAt(pt,
Part.FindAncestor,
p => !this.Diagram.SelectedParts.Contains§,
SearchLayers.Parts).FirstOrDefault();
this.DragOverPart = overpart;

It seems to find my node is over an other only after its center over my second and I would to applicate it to my entire node…

How could I do that? When I drop a node into a group, my node can overlap and I would like to avoid that… :$

This is my nodeTemplate :

            <go:NodePanel  Sizing="Auto" >
                <Path go:NodePanel.Figure="RoundedRectangle" Fill="WhiteSmoke"
                      Stroke="{Binding Path=Data.Highlight, Converter={StaticResource theStrokeChooser}}"
                    go:Node.LinkableFrom="True" go:Node.LinkableTo="True" Cursor="Hand"/>
                <StackPanel x:Name="Shape" Orientation="Vertical">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0 0 0 10">
                        <Image x:Name ="ImageData" Source="/Images/zoom.bmp" Stretch="Fill" Width="20" Height="20"/>
                        <TextBlock HorizontalAlignment="Center"
                        Text="{Binding Path=Data.Title}" FontSize="16" FontWeight="Bold" TextWrapping="Wrap" go:Part.TextEditable="True"
                        Foreground="{Binding Path=Data.Color, Converter={StaticResource theStringBrushConverter}}"/>
                    </StackPanel>

                    <StackPanel Margin="0 0 0 10" >
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <grid:DataGrid Grid.Row="0" AutoGenerateColumns="False" CanUserResizeColumns="False"
                     Background="White" HorizontalAlignment="Stretch"
                     ItemsSource="{Binding Path=Data.Items}" HeadersVisibility="None" BorderBrush="White">
                                <grid:DataGrid.Columns>
                                    <grid:DataGridTemplateColumn>
                                        <grid:DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <go:NodePanel>
                                                    <Path go:NodePanel.Figure="{Binding Path=Figure}"
                                            Width="10" Height="10"
                                            Fill="{Binding Path=Color}"
                                            Stroke="Black" StrokeThickness="1"/>
                                                </go:NodePanel>
                                            </DataTemplate>
                                        </grid:DataGridTemplateColumn.CellTemplate>
                                    </grid:DataGridTemplateColumn>
                                    <grid:DataGridTextColumn Binding="{Binding Path=Name}"/>
                                    <grid:DataGridTextColumn Binding="{Binding Path=Value}"/>
                                </grid:DataGrid.Columns>
                            </grid:DataGrid>
                        </Grid>
                    </StackPanel>
                    <StackPanel x:Name="panel_buttonNode">
                        <Button x:Name="buttonNode" Content="AjoutBoutton" Click="buttonNode_Click" Margin="5 5 5 5"/>
                    </StackPanel>
                </StackPanel>
                <ToolTipService.ToolTip>
                    <TextBlock Text="{Binding Path=Data.Key}"
                 Visibility="{Binding Path=Data.Key.Length,
                              Converter={StaticResource theCountVisibilityConverter}}" />
                </ToolTipService.ToolTip>
       </go:NodePanel>

            <Rectangle Fill="Black" Width="4" Height="4"
             go:SpotPanel.Spot="{Binding Path=Data.Spot1}" go:SpotPanel.Alignment="{Binding Path=Data.Spot1}"
             go:Node.PortId="S1" go:Node.LinkableFrom="True" go:Node.LinkableTo="True" Cursor="Hand"
             go:Node.FromSpot="{Binding Path=Data.Spot1}" go:Node.ToSpot="{Binding Path=Data.Spot1}" />
            <Rectangle Fill="Black" Width="4" Height="4"
             go:SpotPanel.Spot="{Binding Path=Data.Spot2}" go:SpotPanel.Alignment="{Binding Path=Data.Spot2}"
             go:Node.PortId="S2" go:Node.LinkableFrom="True" go:Node.LinkableTo="True" Cursor="Hand"
             go:Node.FromSpot="{Binding Path=Data.Spot2}" go:Node.ToSpot="{Binding Path=Data.Spot2}" />
            <Rectangle Fill="Black" Width="4" Height="4"
             go:SpotPanel.Spot="{Binding Path=Data.Spot3}" go:SpotPanel.Alignment="{Binding Path=Data.Spot3}"
             go:Node.PortId="S3" go:Node.LinkableFrom="True" go:Node.LinkableTo="True" Cursor="Hand"
             go:Node.FromSpot="{Binding Path=Data.Spot3}" go:Node.ToSpot="{Binding Path=Data.Spot3}" />
            <Rectangle Fill="Black" Width="4" Height="4"
             go:SpotPanel.Spot="{Binding Path=Data.Spot4}" go:SpotPanel.Alignment="{Binding Path=Data.Spot4}"
             go:Node.PortId="S4" go:Node.LinkableFrom="True" go:Node.LinkableTo="True" Cursor="Hand"
             go:Node.FromSpot="{Binding Path=Data.Spot4}" go:Node.ToSpot="{Binding Path=Data.Spot4}" />
        </go:SpotPanel>
    </DataTemplate>

You’ll notice that your code to find nodes that it is over is depending on a Point (“pt”) that I assume is the position of the mouse point in document coordinates. That means it is looking for nodes at that point, not that intersect with the nodes that are selected and being dragged.

If you want that behavior, you will have to change the code to look for intersections. Use the DiagramPanel.FindPartsIn method. If there are multiple nodes that are being dragged, you will need to figure out what you want to do with each one.

I understand what you mean, but when I drop a node in my group, node can overlap, and this I don’t know how I could fixe it :$

I can forbid the user to drag a node over an other but If the user drop a node into my group, I don’t know what to do…

If you have specified the Group.Layout, when a Node (or a Link) is added as a member of the Group the layout will position the nodes within the group, typically without having the nodes overlap each other.

I use this template, adding golayout:ForceDirectedLayout

<StackPanel Orientation="Vertical" go:Node.LocationElementName="myGroupPanel" go:Part.DragOverSnapEnabled="True" go:Part.DropOntoBehavior="AddsToGroup"
                    go:Part.Movable="True"
                    go:Part.SelectionAdorned="True">

            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                <TextBlock Text="{Binding Path=Data.Key}" FontWeight="Bold" />
                <Button x:Name="myCollapseExpandButton" Click="CollapseExpandButton_Click"
                                    Content="-" Width="20" Height="20" Margin="10 0 0 0"/>
            </StackPanel>

            <StackPanel>
                <go:NodePanel Sizing="Auto" 
                               MinWidth="50" MinHeight="20">
                    
                    <Path go:NodePanel.Figure="RoundedRectangle" Fill="WhiteSmoke" 
                          Stroke="{Binding Path=Node.IsDropOntoAccepted, Converter={StaticResource theStrokeChooser}}"/>

                    <go:GroupPanel x:Name="myGroupPanel" 
                                        go:Group.IsSubGraphExpanded="True"
                                       AllowDrop="True"
                                       SurroundsMembersAfterDrop="True"/>
                    <go:Group.Layout>
                        <golayout:ForceDirectedLayout />
                    </go:Group.Layout>
                </go:NodePanel>
            </StackPanel>
        </StackPanel>
    </DataTemplate>

But when I had a node, I can have this :

I have the same issu that I already told you (when I drag a node) but in this case I don’t know how I can tell my node not to only focus on their center…

You’re still not setting the go:Group.Layout attached property on the root visual element of the Group’s DataTemplate.

Isn’t it what I do when I put this? :$

go:Group.Layout
<golayout:ForceDirectedLayout />

</go:Group.Layout>

You’re putting it on the NodePanel, not on the outermost StackPanel.

BTW, the innermost StackPanel is superfluous.

I did that but it is worst :

<StackPanel Orientation="Vertical" go:Node.LocationElementName="myGroupPanel" go:Part.DragOverSnapEnabled="True" go:Part.DropOntoBehavior="AddsToGroup"
                    go:Part.Movable="True"
                    go:Part.SelectionAdorned="True">

            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                <TextBlock Text="{Binding Path=Data.Key}" FontWeight="Bold" />
                <Button x:Name="myCollapseExpandButton" Click="CollapseExpandButton_Click"
                                    Content="-" Width="20" Height="20" Margin="10 0 0 0"/>
            </StackPanel>

                <go:NodePanel Sizing="Auto" 
                               MinWidth="50" MinHeight="20">
                    
                    <Path go:NodePanel.Figure="RoundedRectangle" Fill="WhiteSmoke" 
                          Stroke="{Binding Path=Node.IsDropOntoAccepted, Converter={StaticResource theStrokeChooser}}"/>

                    <go:GroupPanel x:Name="myGroupPanel" 
                                        go:Group.IsSubGraphExpanded="True"
                                       AllowDrop="True"
                                       SurroundsMembersAfterDrop="True"/>
                    
                </go:NodePanel>
            <go:Group.Layout>
                <golayout:ForceDirectedLayout />
            </go:Group.Layout>
        </StackPanel>
    </DataTemplate>

I don’t understand what’s wrong, sry for asking you so many questions… I thinck i am going to let my node overlap each other…

I at least try to avoid averlapping when the user drag and drop them :

MyData data = this.Diagram.SelectedPart.Data as MyData;
Rect rect = new Rect(pt.X, pt.Y, data.Width, data.Height);
IEnumerable list = this.Diagram.Panel.FindPartsIn(rect ,SearchFlags.Nodes, SearchInclusion.Inside, SearchLayers.Nodes);
MessageBox.Show(list.Count() + “”, “Alert”, MessageBoxButton.OK);

my list seems to be empty all the time, have you an idea why? :$

I don’t know what you want to do. Are you sure that you want SearchInclusion.Inside rather than Intersects?