Search code examples
c#wpfshapesuielement

How can we make an class that contains multiple uielements and acts as a uielement


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,...);


Solution

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