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;
}
}
}
请阅读http://msdn.microsoft.com/en-us/magazine/cc337899.aspx,然后努力不要在get_DefiningGeometry()中调用new。虽然它不是强制性的,但它确实可以在以后为您节省一些问题 – quetzalcoatl