public HomeworkItem(HomeworkTask task, Windows.UI.Color c, UIElementCollection container = null, Module module = null)
        {
            this.InitializeComponent();
            self = task;

            //initial values
            root.Background      = new SolidColorBrush(c);
            _description.Text    = self.Notes;
            completedSwitch.IsOn = self.Completed;
            dateButton.Content   = CoreTime.FormatTime(task.DueOn);



            deleteButton.Tapped += (e, ev) =>
            {
                //OnDelete(this);
                container.Remove(this);
                module.Homeworks.Remove(self);
            };
            completedSwitch.Toggled += (e, ev) =>
            {
                self.Completed = completedSwitch.IsOn;
                // OnChange();
            };
            _description.TextChanged += (e, ev) =>
            {
                Validator.isStringValid(
                    target: _description.Text, scope: "description", allowDigits: true, allowEmpty: true, max: Validator.HomeworkDescriptionMax,
                    autoFix: true, fixTarget: _description, autoNotify: true);
                self.Notes = _description.Text;
                //OnChange();
            };

            dateButton.Click += (e, ev) =>
            {
                introDate.Begin();
            };
            datePicker.BackPressed += (time) =>
            {
                exitDate.Begin();
                dateButton.Content = CoreTime.FormatTime(time);
                self.DueOn         = time;
                //OnChange();
            };
        }
        public HomeworkPreviewComponent(HomeworkTask hw, string module_name, Color c)
        {
            this.InitializeComponent();
            //initial values
            module.Text       = module_name;
            content.Text      = hw.Notes;
            module.Foreground = new SolidColorBrush(c);
            border.Background = new SolidColorBrush(c);
            int left = (hw.DueOn - DateTime.Now).Days;

            if (left == 0)
            {
                time.Text = "Today";
            }
            else
            {
                time.Text = left.ToString() + " days left";
            }

            if (left < 0)
            {
                time.Text = "OVERDUE";           //negative left means due date passed.
            }
            //set colors to indicate proximity of date
            if (left < 5)
            {
                time.Foreground = new SolidColorBrush(Colors.Red);
            }
            else if (left < 14)
            {
                time.Foreground = new SolidColorBrush(Colors.Orange);
            }
            else
            {
                time.Foreground = new SolidColorBrush(Colors.Green);
            }
        }
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            self = (e.Parameter as object[])[1] as Course;

            title.Foreground = new SolidColorBrush(self.TileColor);
            back.Foreground  = new SolidColorBrush(self.TileColor);
            add.Foreground   = new SolidColorBrush(self.TileColor);

            title.Text = self.Name + " homework";

            bool isPinned = false;

            foreach (SecondaryTile tl in await SecondaryTile.FindAllForPackageAsync())
            {
                if (tl.TileId == self.Name.Replace(" ", "") + "homework")
                {
                    pin.Icon = "";
                    isPinned = true;
                }
            }
            pin.Tapped += async(a, b) =>
            {
                Uri           logo = new Uri("ms-appx:///Assets/TileLogo.png");
                SecondaryTile tile = new SecondaryTile();
                tile.BackgroundColor = self.TileColor;
                tile.TileId          = self.Name.Replace(" ", "") + "homework";
                tile.Logo            = logo;
                tile.ForegroundText  = ForegroundText.Light;
                tile.DisplayName     = "HomeworkEditor for " + self.Name;
                tile.ShortName       = self.Name + " homework";
                tile.TileOptions     = TileOptions.ShowNameOnLogo;
                tile.Arguments       = "homework," + ((e.Parameter as object[])[0] as StudentDataBundle).Name + "," + self.Name;
                if (!isPinned)
                {
                    isPinned = await tile.RequestCreateAsync();

                    pin.Icon = "";
                }
                else
                {
                    isPinned = !await tile.RequestDeleteAsync();

                    pin.Icon = "";
                }
            };
            back.Tapped += async(a, b) =>
            {
                await CoreData.SaveTimetable((e.Parameter as object[])[0] as StudentDataBundle);

                Frame.Navigate(typeof(MainPage), (e.Parameter as object[])[0]);
            };

            moduleHolder.fill(self, typeof(HomeworkEditor));
            moduleHolder.OnChosen += (module) =>
            {
                refresh();
            };
            refresh();



            add.Tapped += (q, b) =>
            {
                HomeworkTask bl = new HomeworkTask();
                moduleHolder.Chosen.Homeworks.Add(bl);
                refresh();
            };
        }