private void add_instance(object sender, Windows.UI.Xaml.RoutedEventArgs e) { Instance instance = new Instance { Day = 0, StartTime = new Time { Hours = 9, Minutes = 0 }, EndTime = new Time { Hours = 10, Minutes = 0 }, EventName = temp.Name }; temp.Instances.Add(instance); var control = new InstanceControl(instance, self); holder.Children.Add(control); control.InstanceChanged += () => { ShouldSave = true; }; control.OnDelete += (instanceElement, ins) => { temp.Instances.Remove(ins); holder.Children.Remove(instanceElement); ShouldSave = true; }; }
//this method recreates the content of the holder after an update to the data source void refresh() { holder.Children.Clear(); foreach (Instance c in self.Instances) { InstanceControl cont = new InstanceControl(c, selfTB); holder.Children.Add(cont); cont.OnDelete += (a, b) => { holder.Children.Remove(a); self.Instances.Remove(b); }; } }
void list_SelectionChanged(ref Course model, bool no_selection) { if (!no_selection) { noSelectionGrid.Visibility = Windows.UI.Xaml.Visibility.Collapsed; SelectionGrid.Visibility = Windows.UI.Xaml.Visibility.Visible; actual = model; temp.Clone(model); clear(); _class.Text = model.Class; _teacher.Text = model.Teacher; _notes.Text = model.Notes; _title.Text = model.Name; colorChooser.SelectedColor = model.TileColor; for (int x = 0; x < temp.Instances.Count; x++) { Instance target = temp.Instances[x]; InstanceControl cc = new InstanceControl(target, self); holder.Children.Add(cc); cc.InstanceChanged += () => { ShouldSave = true; }; cc.OnDelete += (sender, instance) => { temp.Instances.Remove(instance); holder.Children.Remove(sender); ShouldSave = true; }; } } else { SelectionGrid.Visibility = Windows.UI.Xaml.Visibility.Collapsed; noSelectionGrid.Visibility = Windows.UI.Xaml.Visibility.Visible; } ShouldSave = false; }