Resizing Node When Dropped Onto Diagram

I would like to have my nodes a standard size in the palette, but then re-size to another size when dragged onto my diagram.

My node template looks like this:


<DataTemplate x:Key="Separator">
        <go:SpotPanel                      
            go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}"
            go:Node.LocationSpot="Center"
            go:Part.Resizable="False"
            go:Part.ResizeElementName="Container"
            go:Part.Reshapable="False"
            go:Part.SelectionAdorned="True"
            go:Part.SelectionElementName="Container">

            <Grid Name="Container"
                  Height="{Binding Path=Data.Height, Mode=TwoWay}"
                  Width="{Binding Path=Data.Width, Mode=TwoWay}">
                <Grid Background="White"
                      go:Node.PortId="" go:Node.LinkableFrom="True" go:Node.LinkableTo="True" Cursor="Hand"
                      go:Node.FromSpot="AllSides" go:Node.ToSpot="AllSides">
                    <FrameworkElement.ToolTip>
                        <TextBlock Text="{Binding Path=Data.Text}" />
                    </FrameworkElement.ToolTip>
                    
                    <Viewbox Stretch="Fill">
                        <Grid>
                            <Path StrokeThickness="1.5" Stroke="#ff000000" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeLineJoin="Round" Fill="#ffffffff" Data="F1 M 84.696,22.195 C 84.696,10.489 65.959,1.000 42.848,1.000 C 19.736,1.000 1.000,10.489 1.000,22.195 C 1.000,33.901 19.736,43.391 42.848,43.391 C 65.959,43.391 84.696,33.901 84.696,22.195 Z"/>
                            <Path StrokeThickness="1.5" Stroke="#ff000000" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeLineJoin="Round" Fill="#ffffffff" Data="F1 M 84.696,202.993 C 84.696,191.286 65.959,181.797 42.848,181.797 C 19.736,181.797 1.000,191.286 1.000,202.993 C 1.000,214.698 19.736,224.188 42.848,224.188 C 65.959,224.188 84.696,214.698 84.696,202.993 Z"/>
                            <Path StrokeThickness="1.5" Stroke="#ff000000" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeLineJoin="Round" Fill="#ffffffff" Data="F1 M 84.696,204.260 L 1.000,204.260 L 1.000,22.014 L 84.696,22.014 L 84.696,204.260 Z"/>
                        </Grid>
                    </Viewbox>
                </Grid>
                
                <Rectangle Fill="Transparent" Margin="13" />
            </Grid>

            <Rectangle Fill="Transparent" Width="6" Height="6"
                           Stroke="{Binding Path=Node.Tag, Converter={StaticResource theStrokeChooser}}"
                           go:SpotPanel.Spot="MiddleLeft" go:SpotPanel.Alignment="MiddleLeft"
                           go:Node.PortId="L" go:Node.LinkableFrom="True" go:Node.LinkableTo="True" Cursor="Hand"                           
                           go:Node.FromSpot="MiddleLeft" go:Node.ToSpot="MiddleLeft" />
            <Rectangle Fill="Transparent" Width="6" Height="6"
                           Stroke="{Binding Path=Node.Tag, Converter={StaticResource theStrokeChooser}}"
                           go:SpotPanel.Spot="MiddleTop" go:SpotPanel.Alignment="MiddleTop"
                           go:Node.PortId="T" go:Node.LinkableFrom="True" go:Node.LinkableTo="True" Cursor="Hand"
                           go:Node.FromSpot="MiddleTop" go:Node.ToSpot="MiddleTop" />
            <Rectangle Fill="Transparent" Width="6" Height="6"
                           Stroke="{Binding Path=Node.Tag, Converter={StaticResource theStrokeChooser}}"
                           go:SpotPanel.Spot="MiddleRight" go:SpotPanel.Alignment="MiddleRight"
                           go:Node.PortId="R" go:Node.LinkableFrom="True" go:Node.LinkableTo="True" Cursor="Hand"
                           go:Node.FromSpot="MiddleRight" go:Node.ToSpot="MiddleRight" />
            <Rectangle Fill="Transparent" Width="6" Height="6"
                           Stroke="{Binding Path=Node.Tag, Converter={StaticResource theStrokeChooser}}"
                           go:SpotPanel.Spot="MiddleBottom" go:SpotPanel.Alignment="MiddleBottom"
                           go:Node.PortId="B" go:Node.LinkableFrom="True" go:Node.LinkableTo="True" Cursor="Hand"
                           go:Node.FromSpot="MiddleBottom" go:Node.ToSpot="MiddleBottom" />
        </go:SpotPanel>
    </DataTemplate>

private void myDiagram_Drop(object sender, DragEventArgs e)
        {
            Node node = ((Diagram)sender).Nodes.Last();

            node.Resizable = true;
            node.Rotatable = true;

            ItemData data = node.Data as ItemData;

            data.Height = data.DiagramHeight;
            data.Width = data.DiagramWidth;
            
            node.MouseEnter += ShowPorts;
            node.MouseLeave += HidePorts;
        }

data.DiagramHeight and data.DiagramWidth have the size values that I would like the node to be re-sized to when dropped on the diagram. I thought changing the values on data.Height and data.Width would update the size of the node in the diagram as they are data-bound in the data template. This seems like it should be really simple, what am I missing?

Thanks
Ryan

You can make the nodes in one diagram look completely different from those in another diagram, even when representing exactly the same data. Just customize the template(s) the way you want. No code needed.

Right, but I want it to look the same and just change size once the node has been dropped onto the diagram. How can I resize the node in code?

Perhaps the Diagram.Drop event isn’t happening when you’d expect it to?

Usually I’d implement a Diagram.ExternalObjectsDropped event handler.
Look at the Diagram.SelectedParts to see what’s just been dropped.

Diagram.ExternalObjectsDropped seems to have done the trick, thanks.