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