icsharpcode / WpfDesigner

The WPF Designer from SharpDevelop
MIT License
958 stars 259 forks source link

BorderForMouseOver of Line control is not displayed at correct position #115

Closed YuuukiA closed 3 weeks ago

YuuukiA commented 2 months ago

For Line control, BorderForMouseOver is not displayed at correct position. Would you please tell me how to fix it?

When I draw Line control from the top left to the bottom right, the border is displayed at correct position. image

When I draw Line control from the top right to the bottom left, the border is not displayed at correct position. image

YuuukiA commented 1 month ago

I have avoided it by modifying BorderForMouseOver.cs as the following.

public class BorderForMouseOver : AdornerProvider
{
  readonly AdornerPanel adornerPanel;
  private readonly Border _border = new Border();

  public BorderForMouseOver()
  {
    adornerPanel = new AdornerPanel();
    adornerPanel.Order = AdornerOrder.Background;
    this.Adorners.Add(adornerPanel);
    _border.BorderThickness = new Thickness(1);
    _border.BorderBrush = Brushes.DodgerBlue;
    _border.Margin = new Thickness(-2);
    AdornerPanel.SetPlacement(_border, AdornerPlacement.FillContent);
    adornerPanel.Children.Add(_border);
  }

  protected override void OnInitialized()
  {
      base.OnInitialized();

      if (ExtendedItem.Component is Line line)
      {
          // To display border of Line in correct position.
          _border.Margin = new Thickness
          {
              Left = line.X2 < 0 ? line.X2 : 0,
              Top = line.Y2 < 0 ? line.Y2 : 0
          };
      }
  }
}
jogibear9988 commented 1 month ago

Could you create a pull req?