/// <summary> /// Show an <see cref="Adornment"/> with resize handles at points along the edge of bounds of the <see cref="AdornedElement"/>, /// if the node is selected and visible and if <see cref="Northwoods.GoXam.Part.CanResize"/> is true. /// </summary> /// <param name="part"></param> /// <remarks> /// <para> /// First this finds the element in the visual tree of the <paramref name="part"/> that should /// get the resize adornment and that the user will be able to resize interactively. /// It finds the element that has the <see cref="Part.ResizeElementName"/> property of the part. /// If the <see cref="Part.ResizeElementName"/> property is null, as it is by default, it uses /// the part's <see cref="Part.SelectionElement"/>. /// </para> /// <para> /// It then constructs the adornment template, associating it with the chosen resize element. /// </para> /// <para> /// You can change the template used to create the adornment by setting <see cref="Part.ResizeAdornmentTemplate"/>. /// If that property is null, this uses a default template with eight resize handles /// at the four corners and at the middles of the four sides. /// </para> /// <para> /// This only gives a resize adornment to <see cref="Node"/>s, not to <see cref="Link"/>s. /// </para> /// </remarks> public override void UpdateAdornments(Part part) { if (part == null || part is Link) { return; // can't resize links } Adornment adornment = null; if (part.IsSelected) { FrameworkElement selelt = null; String eltname = part.ResizeElementName; if (eltname != null) { selelt = part.FindNamedDescendant(eltname); } if (selelt == null) { selelt = part.SelectionElement; } if (selelt != null && part.CanResize() && Part.IsVisibleElement(selelt)) { adornment = part.GetAdornment(ToolCategory); if (adornment == null) { DataTemplate template = part.ResizeAdornmentTemplate; if (template == null) { template = Diagram.FindDefault <DataTemplate>("DefaultResizeAdornmentTemplate"); } adornment = part.MakeAdornment(selelt, template); if (adornment != null) { adornment.Category = ToolCategory; adornment.LocationSpot = Spot.TopLeft; } } if (adornment != null) { Node node = (Node)part; Point loc = part.GetElementPoint(selelt, Spot.TopLeft); // use the node's angle, not part.GetAngle(selelt) //?? this can be wrong if there are additional rotational transforms in the tree double angle = node.RotationAngle; UpdateResizeHandles(adornment.VisualElement, angle); adornment.Location = loc; adornment.RotationAngle = angle; adornment.Remeasure(); } } } part.SetAdornment(ToolCategory, adornment); }
/// <summary> /// Show an <see cref="Adornment"/> with resize handles at points along the edge of bounds of the <see cref="AdornedElement"/>, /// if the node is selected and visible and if <see cref="Northwoods.GoXam.Part.CanResize"/> is true. /// </summary> /// <param name="part"></param> /// <remarks> /// You can change the template used to create the adornment by setting <see cref="Part.ResizeAdornmentTemplate"/>. /// If that property is null, this uses a default template with eight resize handles /// at the four corners and at the middles of the four sides. /// </remarks> public override void UpdateAdornments(Part part) { if (part == null || part is Link) { return; // can't resize links } Adornment adornment = null; if (part.IsSelected) { FrameworkElement selelt = part.SelectionElement; if (selelt != null && part.CanResize() && Part.IsVisibleElement(selelt)) { adornment = part.GetAdornment(ToolCategory); if (adornment == null) { DataTemplate template = part.ResizeAdornmentTemplate; if (template == null) { template = Diagram.FindDefault <DataTemplate>("DefaultResizeAdornmentTemplate"); } adornment = part.MakeAdornment(selelt, template); if (adornment != null) { adornment.Category = ToolCategory; adornment.LocationSpot = Spot.TopLeft; } } if (adornment != null) { Point loc = part.GetElementPoint(selelt, Spot.TopLeft); double angle = part.GetAngle(selelt); UpdateResizeHandles(adornment.VisualElement, angle); adornment.Location = loc; adornment.RotationAngle = angle; adornment.Remeasure(); } } } part.SetAdornment(ToolCategory, adornment); }
private void LayoutBox(TextBox box) { if (box == null) { return; } TextEditingTool tool = this.TextEditingTool; if (tool == null) { return; } TextBlock block = tool.TextBlock; if (block == null) { return; } Adornment edad = tool.EditorAdornment; if (edad == null) { return; } Thickness thick = box.BorderThickness; Thickness pad = box.Padding; if (block.TextWrapping != TextWrapping.NoWrap) { double w = MeasureWrappedTextWidth(box.Text, box, block); Size es = edad.GetEffectiveSize(block); double ww = Math.Max(w, es.Width); // at least existing width box.MaxWidth = ww + thick.Left + thick.Right + pad.Left + pad.Right + 6; //??? hard-coded sizes //Diagram.Debug(Diagram.Str(ds) + Diagram.Str(es) + " ww: " + Diagram.Str(ww) + " maxw: " + Diagram.Str(box.MaxWidth)); } edad.Remeasure(); }