椭圆几何自定义形状

发布于 2024-12-02 08:01:12 字数 839 浏览 0 评论 0原文

我从形状中导出来绘制椭圆。绘图从 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;
        }
    }
}

I am deriving from shape to draw an ellipse. The drawing starts at 0,0 so only the bottom right corner of the ellipse its drawn. How do I transform the origin in the overridegeometry method:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

筱果果 2024-12-09 08:01:12

我通过使用

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

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

I fixed it by using

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

Another way would be to set the center property of the ellipse I think to the attributes (I haven't tried this yet).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文