當尋找到代碼深入一點,我發現這是減去所需的寬度和高度x和y的部分,甚至認爲我是不是拖動裝飾者。所以我在他們爲榜樣改變了下面的代碼:
protected override Size ArrangeOverride(Size finalSize)
{
// desiredWidth and desiredHeight are the width and height of the element that's being adorned.
// These will be used to place the ResizingAdorner at the corners of the adorned element.
double desiredWidth = AdornedElement.DesiredSize.Width;
double desiredHeight = AdornedElement.DesiredSize.Height;
// adornerWidth & adornerHeight are used for placement as well.
double adornerWidth = this.DesiredSize.Width;
double adornerHeight = this.DesiredSize.Height;
topLeft.Arrange(new Rect(-adornerWidth/2, -adornerHeight/2, adornerWidth, adornerHeight));
topRight.Arrange(new Rect(desiredWidth - adornerWidth/2, -adornerHeight/2, adornerWidth, adornerHeight));
bottomLeft.Arrange(new Rect(-adornerWidth/2, desiredHeight - adornerHeight/2, adornerWidth, adornerHeight));
bottomRight.Arrange(new Rect(desiredWidth - adornerWidth/2, desiredHeight - adornerHeight/2, adornerWidth, adornerHeight));
// Return the final size.
return finalSize;
}
下面的代碼:
protected override Size ArrangeOverride(Size finalSize)
{
// desiredWidth and desiredHeight are the width and height of the element that's being adorned.
// These will be used to place the ResizingAdorner at the corners of the adorned element.
double desiredWidth = AdornedElement.DesiredSize.Width;
double desiredHeight = AdornedElement.DesiredSize.Height;
// adornerWidth & adornerHeight are used for placement as well.
double adornerWidth = this.DesiredSize.Width;
double adornerHeight = this.DesiredSize.Height;
//Orginal Microsoft code
//topLeft.Arrange(new Rect(-adornerWidth/2, -adornerHeight/2, adornerWidth, adornerHeight));
//topRight.Arrange(new Rect(desiredWidth - (adornerWidth/2), - adornerHeight/2, adornerWidth, adornerHeight));
//bottomLeft.Arrange(new Rect(-adornerWidth/2, desiredHeight - adornerHeight/2, adornerWidth, adornerHeight));
//bottomRight.Arrange(new Rect(desiredWidth - (adornerWidth/2), desiredHeight - adornerHeight/2, adornerWidth, adornerHeight));
topLeft.Arrange(new Rect(-adornerWidth/2, -adornerHeight/2, adornerWidth, adornerHeight));
topRight.Arrange(new Rect(adornerWidth/2, -adornerHeight/2, adornerWidth, adornerHeight));
bottomLeft.Arrange(new Rect(-adornerWidth/2, adornerHeight/2, adornerWidth, adornerHeight));
bottomRight.Arrange(new Rect(adornerWidth/2, adornerHeight/2, adornerWidth, adornerHeight));
// Return the final size.
return finalSize;
}
我沒有經歷過任何怪癖還,但它似乎是正確的。