Bounding box cutting of edges on custom ellipse
I have a custom ellipse code shown bellow. I draw a rubber band using the ellipse setting the width and height using two points, code shown bellow. However when I draw the ellipse the bounding box is cutting of the edges on the sides. I solved this issue before with using actual height and width, but this was in a stand alone application. When I integrated it with the rubber band drawing part, actual height and width don't work anymore, for some reason they don't get updated when I set the width and height. Do you know how can I fix it so that the edges don't get cut off.
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);
开发者_如何学JAVA 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);
Try to compensate for the StrokeThickness, like
ellipse.RadiusX = (this.Width / 2) - StrokeThickness / 2;
ellipse.RadiusY = (this.Height / 2) - StrokeThickness / 2;
精彩评论