Selected parts, apply same width

Objective: User selects objects, when a user clicks ‘set same width button’, the diagram would take the last selected object and apply that width to the other objects.

Question 1: Does diagram.SelectedPart represent the last selected object? If so, using CTRL + selection does not update this property.
Question 2: What is the right way to update width property of controls? This does not seem to work properly. I checked and it's set to NaN in the debugger prior to me setting the width.
foreach (var node in diagram.SelectedParts.OfType<Node>()){
node.Width = width;
Thank you,
Pavel
public void SameWidth()
{
Diagram diagram = this.Diagram;
diagram.StartTransaction(TranscationName.SameWidth);

try

{
var width = diagram.SelectedPart.ActualWidth;
foreach (var node in diagram.SelectedParts.OfType<Node>())
{
node.Width = width;
}
diagram.CommitTransaction(TranscationName.SameWidth);
}
catch (Exception){
diagram.RollbackTransaction();
}
}
  1. No, Diagram.SelectedPart might be the last selected Part, but it usually isn’t if there is a multiple selection.

Look at the Diagram.SelectedParts collection to find the last one. (Caution: what are you going to do if the user selects links?)

  1. You shouldn’t be trying to set the Width or Height of Nodes. Instead, set the Width or Height of the FrameworkElement that governs the size of the Node. That might be the top (or root) element of the Node, but it might be something inside your visual tree, for example a Shape inside some ContentControls or Panels.