private void CorrectSelection(int k, IEnumerable <int> newSelected) { var partToChange = string.Format("PART_Day_{0}", k); TextBlock text = GetTemplateChild(partToChange) as TextBlock; var value = YearMonthArray(); var year = Convert.ToInt16(value[0]); var month = Convert.ToInt16(value[1]); int day = SelectedDay.GetDayIndex(text); // this keys keep in account the offset used while drawing. var effectiveKey = filterLimit(day, MonthIndex, year); if (text != null) { if (SelectedDay.GetIsDaySelected(text)) { // looking for a selected value that it shall be not selected anymore. if (!newSelected.Contains(effectiveKey)) { SelectedDay.SetIsDaySelected(text, false); text.Background = Brushes.White; } } } }
private void Text_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { TextBlock currentButton = sender as TextBlock; if (currentButton != null) { int day = SelectedDay.GetDayIndex(currentButton); int mIndex = MonthIndex; // i shall check if i can stay on the ranges. var value = YearMonthArray(); var year = Convert.ToInt16(value[0]); var month = Convert.ToInt16(value[1]); day = filterLimit(day, mIndex, year); var param = CreateCommand(day, false); List <int> daysOff = DaysOff.ToList(); // avoid correction if it i have just clicked. if (SelectedDay.GetIsDaySelected(currentButton)) { currentButton.Background = Brushes.White; daysOff.Remove(day); SelectedDay.SetIsDaySelected(currentButton, false); } else { param = CreateCommand(day, true); currentButton.Background = Brushes.Yellow; daysOff.Add(day); SelectedDay.SetIsDaySelected(currentButton, true); } DaysOff = daysOff; // this make in a way that the reset command is internally called. if ((_resetCommand != null) && (!_resetCommand.Equals(ResetCommand))) { ResetCommand = _resetCommand; } if (SelectedDayCommand != null) { SelectedDayCommand.Execute(param); } } }