1

我从形状派生来画一个椭圆。绘图从 0,0 开始,因此仅绘制椭圆的右下角。如何在 overridegeometry 方法中转换原点:

class Ellipse2 : Shape
{
    EllipseGeometry ellipse;
    public static readonly DependencyProperty TextBoxRProperty = DependencyProperty.Register("TextBoxR", typeof(TextBox), typeof(Ellipse2), new FrameworkPropertyMetadata(null));
    public TextBox TextBox
    {
        get { return (TextBox)GetValue(TextBoxRProperty); }
        set { SetValue(TextBoxRProperty, value); }
    }
    public Ellipse2()
    {
        ellipse = new EllipseGeometry();

        this.Stroke = Brushes.Gray;
        this.StrokeThickness = 3;
    }
    protected override Geometry DefiningGeometry
    {
        get
        {
            ellipse.RadiusX = this.Width/2;
            ellipse.RadiusY = this.Height/2;

            return ellipse;
        }
    }
}
4

1 回答 1

2

我通过使用修复它

protected override Geometry DefiningGeometry 
{ 
   get 
   { 
   TranslateTransform t = new TranslateTransform(ActualWidth / 2, ActualHeight / 2);        
   ellipse.Transform = t; 
   ellipse.RadiusX = this.ActualWidth/2; 
   ellipse.RadiusY = this.ActualHeight/2; 
   return ellipse; 
   } 
}

另一种方法是将我认为的椭圆的中心属性设置为属性(我还没有尝试过)。

于 2011-09-07T22:55:59.383 回答