0

以下に示すカスタム楕円コードがあります。幅と高さを2点で設定した楕円を使用して輪ゴムを描きます。コードは次のとおりです。ただし、楕円を描くと、バウンディングボックスは側面のエッジをカットしています。以前、実際の高さと幅を使用してこの問題を解決しましたが、これはスタンドアロンアプリケーションでした。輪ゴム製図部分と統合すると、実際の高さや幅が機能しなくなり、幅や高さを設定してもどういうわけか更新されません。エッジが切れないように修正する方法を知っていますか。

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

1 に答える 1

1

次のように、StrokeThicknessを補正してみてください

ellipse.RadiusX = (this.Width / 2) - StrokeThickness / 2;
ellipse.RadiusY = (this.Height / 2) - StrokeThickness / 2;
于 2011-08-31T17:44:13.223 に答える