0
我有一個自定義的橢圓代碼如下所示。我使用橢圓設置寬度和高度,使用兩點繪製橡皮筋,代碼如下所示。然而,當我繪製橢圓時,邊界框會切割邊上的邊。我之前使用實際的高度和寬度解決了這個問題,但這是一個獨立的應用程序。當我將它與橡皮筋繪圖部件集成在一起時,實際的高度和寬度不再起作用,由於某些原因,當我設置寬度和高度時,它們不會更新。你知道我該如何解決這個問題,以便邊緣不會被切斷。邊框在自定義橢圓上的邊緣切割
namespace WpfApplication4
{
class Ellipse2 : Shape
{
EllipseGeometry ellipse;
public static readonly DependencyProperty TextBoxShapeProperty = DependencyProperty.Register("TextBoxShape", typeof(TextBoxShape), typeof(Ellipse2), new FrameworkPropertyMetadata(null));
public TextBoxShape TextBoxShape
{
get { return (TextBoxShape)GetValue(TextBoxShapeProperty); }
set { SetValue(TextBoxShapeProperty, value); }
}
public Ellipse2()
{
ellipse = new EllipseGeometry();
this.Fill = Brushes.Transparent;
this.Stroke = Brushes.Gray;
this.StrokeThickness = 3;
}
protected override Geometry DefiningGeometry
{
get
{
TranslateTransform t = new TranslateTransform(Width/2, Height/2);
ellipse.Transform = t;
ellipse.RadiusX = this.Width/2;
ellipse.RadiusY = this.Height/2;
return ellipse;
}
}
}
}
double width = Math.Abs(initMousePoint.X - currMousePoint.X);
double height = Math.Abs(initMousePoint.Y - currMousePoint.Y);
double left = Math.Min(initMousePoint.X, currMousePoint.X);
double top = Math.Min(initMousePoint.Y, currMousePoint.Y);
rubberBandShape.Width = width;
rubberBandShape.Height = height;
Canvas.SetTop(rubberBandShape, top);
Canvas.SetLeft(rubberBandShape, left);
請停止(http://meta.stackexchange.com/questions/10647/howto-writing- [在你的問題標題前加上標籤]好標題/ 10651#10651),這不是必要的,頁面標題會自動添加最受歡迎的標籤。 –
「Ellipse2」切割邊緣的唯一問題是什麼?我試了一下,似乎沒有處理像'Margin'等東西。無論如何,嘗試補償'StrokeThickness',就像'ellipse.RadiusX =(this.Width/2) - StrokeThickness/2;' –
@Meleak感謝它的完美運作,我不知道我是怎麼想的。如果你願意,可以將它發佈爲答案,我會接受它。您是否知道爲什麼實際的高度和寬度不會更新? – mihajlv