public void UpdateCurrentTask()
        {
            if (this.Tasks == null || this.Tasks.Count() == 0)
            {
                return;
            }

            if (CurrentTask == null)
            {
                CurrentTask = this.Tasks[0];
            }

            int currentIndex = this.Tasks.IndexOf(CurrentTask);

            if (currentIndex == (Tasks.Count - 1))
            {
                return;
            }

            TaskSectionControl c = null;

            if (!taskSections.TryGetValue(CurrentTask, out c))
            {
                return;
            }

            if (CurrentTask.TimeLeft.IsOutOfTime)
            {
                if (AutoSwitchToNextTask)
                {
                    int currentTaskEnds = this.Tasks.Take(currentIndex + 1).Sum(x => x.OriginalTime.TotalSeconds);
                    if (ElapsedTime < currentTaskEnds)
                    {
                        return;
                    }

                    CurrentTask = Tasks[currentIndex + 1];
                }
                else
                {
                    //Adjust widths here.
                    UpdateSections();
                }
            }
        }
        public void InitializeRectangles()
        {
            this.RectangleGrid.ColumnDefinitions.Clear();
            this.RectangleGrid.Children.Clear();

            ClearExistingTaskSections();
            if (this.TotalTime == null || !this.TotalTime.IsPositiveTime || Tasks == null)
            {
                return;
            }

            int i = 0;

            foreach (var task in Tasks)
            {
                TaskSectionControl section = new TaskSectionControl(task);
                int maxTime = Math.Max(task.OriginalTime.TotalSeconds, task.ElapsedTime.TotalSeconds);
                section.WidthPercentage = (double)
                                          (
                    ((double)maxTime) / ((double)this.TotalTime.TotalSeconds)
                                          );
                section.Width = this.ActualWidth * section.WidthPercentage;

                //New column definition
                var def = new ColumnDefinition();// { Width = new GridLength(width) };
                this.RectangleGrid.ColumnDefinitions.Add(def);
                def.Width = new GridLength(section.WidthPercentage, GridUnitType.Star);

                //Section
                section.Height = this.ActualHeight;
                this.RectangleGrid.Children.Add(section);
                Grid.SetColumn(section, i);
                ++i;
                taskSections[task] = section;
            }

            UpdateCurrentTask();
        }