1

We would like to make a little drawing application and i don't know how to make a class derived from shape or uielement or something else that contains multiple objects like a line and text or multiple lines that are not connected. How would i do that?

For an ellipse i have this:

public class B_Null : Shape
{
    EllipseGeometry eg;
    public double Breedte { get; private set; }

    public B_Null()
    {
        Stroke = Brushes.Red;
        StrokeThickness = 1;
        Fill = Brushes.Red;
        eg = new EllipseGeometry(new Point(100, 100), 100, 100);
        Breedte = 200;
    }

    protected override Geometry DefiningGeometry
    {
        get
        {
            return eg;
        }
    }

}

The above works but it cannot handle multiple uielements? (Or multiple lines that are not connected)

The goal is to have one class that contains multiple elements. At the end i want to use this code: Canvas.SetTop(MyUiElement,...);

H.B.
  • 166,899
  • 29
  • 327
  • 400
Gho W
  • 51
  • 1
  • 7
  • Why not inherit from Canvas? – tym32167 Sep 13 '16 at 11:38
  • Inheritance from Controls in WPF can be a real pain. A far better (i.e. simpler) option is to create your own UserControl that contains a top-level Grid/Canvas item, and then put your various UI elements inside that. – LordWilmore Sep 13 '16 at 15:02
  • You don't need this derived control. Just use an ItemsControl, probably with a Canvas as ItemsPanel. – Clemens Sep 13 '16 at 15:02

1 Answers1

0

Thank you ver much for the information! I inherited my drawing objects from the Canvas and then add all my objects easily on a canvas.

public class B_Null : Canvas
{
    private Ellipse Ellipse = new Ellipse();


    public B_Null()
    {
        Ellipse.Width = 200;
        Ellipse.Height = 200;
        Ellipse.Stroke = Brushes.Red;
        Ellipse.StrokeThickness = 1;
        Ellipse.Fill = Brushes.Red;
        this.Children.Add(Ellipse);
    }



}
Gho W
  • 51
  • 1
  • 7