In my program i have 4 "workPackages" with different start and enddates, this looks like this:
WorkPackage[] workpackages = new WorkPackage[4];
workpackages[0] = new WorkPackage("Package 1", new DateTime(2021, 1, 7), new DateTime(2021, 2, 2));
workpackages[1] = new WorkPackage("Package 2", new DateTime(2021, 1, 1), new DateTime(2021, 4, 1));
workpackages[2] = new WorkPackage("Package 3", new DateTime(2022, 1, 3), new DateTime(2022, 8, 1));
workpackages[3] = new WorkPackage("Package 4", new DateTime(2023, 1, 8), new DateTime(2024, 12, 1));
Then I created rectangles whose length depends on the time span between the date times from the packages. This looks like this:
for (int i = 0; i < workpackages.Length; i++)
{
timeSpan[i] = (workpackages[i].enddate - workpackages[i].startdate).TotalDays;
Rectangle rectangle = new Rectangle
{
Fill = brush,
StrokeThickness = strokethickness,
Stroke = Brushes.Black,
Width = timeSpan[i],
Height = rectangleHeight / howmanyrect - distancebetweenrectangles
};
MyRectangle[i] = rectangle;
Canvas.SetLeft(rectangle, rectangle.Width / 2.0 - rectangle.Width / 2.0);
Canvas.SetTop(rectangle, i * (rectangleHeight / howmanyrect));
myCanvas.Children.Add(rectangle);
Content = myCanvas;
}
And in my WPF window it looke like this:
.
If you know what a Gantt Chart is then it should be familiar to you what I'm trying to do. Now I want the rectangle with the earliest startDate to be on the first spot and then the others in order according to their start- and endDate. For finding the earliest date I did this for loop:
for (int i = 1; i < workpackages.Length; i++)
{
if (workpackages[i].startdate < earliestdate)
{
earliestdate = workpackages[i].startdate;
}
}
So how do I let the program know that the rectangle with the earliest date must be placed on the first spot?