Wpf 自定义椭圆上边的边界框切割

Wpf 自定义椭圆上边的边界框切割,wpf,height,width,ellipse,bounding-box,Wpf,Height,Width,Ellipse,Bounding Box,我有一个自定义椭圆代码如下所示。我用椭圆画了一条橡皮筋,用两点设置宽度和高度,代码如下所示。然而,当我画椭圆时,边界框是边的切割。我以前用实际的高度和宽度解决了这个问题,但这是一个独立的应用程序。当我将其与橡皮筋绘图部分集成时,实际的高度和宽度不再起作用,因为某些原因,当我设置宽度和高度时,它们不会得到更新。你知道我怎样才能把它修好,这样边缘就不会被切断 namespace WpfApplication4 { class Ellipse2 : Shape { E

我有一个自定义椭圆代码如下所示。我用椭圆画了一条橡皮筋,用两点设置宽度和高度,代码如下所示。然而,当我画椭圆时,边界框是边的切割。我以前用实际的高度和宽度解决了这个问题,但这是一个独立的应用程序。当我将其与橡皮筋绘图部分集成时,实际的高度和宽度不再起作用,因为某些原因,当我设置宽度和高度时,它们不会得到更新。你知道我怎样才能把它修好,这样边缘就不会被切断

 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);

试着补偿一下中风,比如

ellipse.RadiusX = (this.Width / 2) - StrokeThickness / 2;
ellipse.RadiusY = (this.Height / 2) - StrokeThickness / 2;

请停止,这不是必需的,页面标题会自动添加最常用的标记。唯一的问题是
Ellipse2
的边缘被切割了吗?我试过了,它似乎不能处理像
边距
之类的东西。无论如何,试着补偿
StrokeThickness
,比如
eliple.RadiusX=(this.Width/2)-StrokeThickness/2@Meleak谢谢它工作得很好,我不知道我怎么会没有想到这一点。如果你愿意,把它作为答案贴出来,我会接受的。顺便问一下,你知道为什么实际高度和宽度没有得到更新吗?@mihajlv:好的,补充了一个答案:)我也尝试了
ActualWidth
ActualHeight
,对我来说效果比
width
height
好。不知道你为什么会有这个问题