/// <summary> /// Invoked when the item currently displayed changes. /// </summary> /// <param name="sender">The FlipView instance for which the current item has changed.</param> /// <param name="e">Event data that describes how the current item was changed.</param> void FlipView_SelectionChanged(object sender, SelectionChangedEventArgs e) { // Enable the previous and next buttons as appropriate try { this.DefaultViewModel["CanFlipNext"] = this.flipView.Items != null && this.flipView.SelectedIndex < (this.flipView.Items.Count - 1); this.DefaultViewModel["CanFlipPrevious"] = this.flipView.SelectedIndex > 0; SampleDataItem item = this.flipView.Items[this.flipView.SelectedIndex] as SampleDataItem; this.pageTitle.Text = "Hindu Calendar - " + item.Title + " " + item.Year.ToString(); this.cityTitle.Text = item.Group.city._Name; FlipViewItem selectedFlipViewItem = (FlipViewItem)this.flipView.ItemContainerGenerator.ContainerFromIndex(flipView.SelectedIndex); if (selectedFlipViewItem != null) { if (_currentHighlightedDateItem != null) { _currentHighlightedDateItem.HighlightBorder(false); } _currentHighlightedDateItem = null; Grid monthView = (Grid)FindNamedElement(selectedFlipViewItem, "monthView"); int month = ((flipView.SelectedIndex) % 12) + 1; BuildCalendar(monthView, month, item); Debug.Assert(_currentHighlightedDateItem != null); DayViewGridStoryboard.Begin(); } } catch (ArgumentException exc) { Debug.WriteLine("Exception is " + exc.Message); Debug.Assert(false); } }
private void dateItem_PointerReleased(object sender, PointerRoutedEventArgs e) { DateItem dateItem = sender as DateItem; // If its a mouse click look for left mouse button click if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse) { Windows.UI.Input.PointerPoint currentPoint = e.GetCurrentPoint(dateItem); Windows.UI.Input.PointerUpdateKind kind = currentPoint.Properties.PointerUpdateKind; if (kind != Windows.UI.Input.PointerUpdateKind.LeftButtonReleased) { return; } } // If the user clicks on the empty squares skip if (dateItem.GetDay() > 0) { try { SampleDataItem item = this.flipView.Items[this.flipView.SelectedIndex] as SampleDataItem; int month = ((flipView.SelectedIndex) % 12) + 1; ShowDetail(month, dateItem.GetDay(), item); dateItem.HighlightBorder(true); DateItem oldItem = _currentHighlightedDateItem; if (oldItem != null) { oldItem.HighlightBorder(false); } _currentHighlightedDateItem = dateItem; } catch (ArgumentOutOfRangeException err) { Debug.WriteLine("Argument out of range" + err); } } }
private void BuildCalendar(Grid monthView, int month, SampleDataItem item) { int row, col; DateItem[,] dateItems; if (monthView.Tag == null) { dateItems = new DateItem[numRows, numCols]; for (row = 0; row < numRows; row++) { for (col = 0; col < numCols; col++) { DateItem dateItem = new DateItem(); dateItem.SetValue(Grid.RowProperty, row); dateItem.SetValue(Grid.ColumnProperty, col); monthView.Children.Add(dateItem); dateItems[row, col] = dateItem; if (row == 0) { DayOfWeek day = (DayOfWeek)col; dateItem.SetDay(_dayStrings[(int)day]); } else { dateItem.SetDay(" "); dateItem.PointerReleased += dateItem_PointerReleased; } } } monthView.Tag = dateItems; } // collapse them all to be opened later dateItems = (DateItem[, ])monthView.Tag; for (row = 1; row < numRows; row++) { for (col = 0; col < numCols; col++) { dateItems[row, col].Visibility = Visibility.Collapsed; } } String previousTamilMonth, tamilMonth; String previousSanskritMonth, sanskritMonth; String previousPaksha, paksha; bool fullMoonDayFound = false; bool newMoonDayFound = false; DateItem currentDateItem = null; row = 1; previousTamilMonth = null; previousSanskritMonth = null; previousPaksha = ""; tamilMonthTitle.Text = ""; sanskritMonthTitle.Text = ""; for (int day = 1; day <= 31; day++) { DateTime dateTime; try { dateTime = new DateTime(item.Year, month, day); col = (int)dateTime.DayOfWeek; String festival, nakshatra; bool isNewMoonDay, isFullMoonDay; bool highlight; item.GetDateData(month, day, out isNewMoonDay, out isFullMoonDay, out festival, out paksha, out nakshatra, out tamilMonth); PanchangData pdata = item.GetPanchangData(month, day); sanskritMonth = pdata._fieldValues[(int)FieldType.SanskritMonth]; if (isNewMoonDay) { newMoonDayFound = true; } if (isFullMoonDay) { fullMoonDayFound = true; } // Sometimes the tithi changes in the middle of the day and is not captured. Lets fix it here if ((previousPaksha.Contains("Shukla") == true) && (paksha.Contains("Krishna") == true) && (fullMoonDayFound == false)) { // Set the previous item to full moon day currentDateItem.SetDay(currentDateItem.GetDay(), false, true, null, null, "KeepExisting"); } // Sometimes the tithi changes in the middle of the day and is not captured. Lets fix it here if ((previousPaksha.Contains("Krishna") == true) && (paksha.Contains("Shukla") == true) && (newMoonDayFound == false)) { // Set the previous item to new moon day currentDateItem.SetDay(currentDateItem.GetDay(), true, false, null, null, "KeepExisting"); } previousPaksha = paksha; currentDateItem = dateItems[row, col]; PrivateEvent evt = null; if (_privateEvents != null) { evt = _privateEvents.GetFirstEventForDate(dateTime); } if (evt != null) { currentDateItem.SetDay(day, isNewMoonDay, isFullMoonDay, evt._eventText, null, nakshatra); } else { currentDateItem.SetDay(day, isNewMoonDay, isFullMoonDay, festival, null, nakshatra); } currentDateItem.Visibility = Visibility.Visible; if (String.Equals(previousTamilMonth, tamilMonth, StringComparison.OrdinalIgnoreCase) == false) { tamilMonthTitle.Text += (previousTamilMonth == null) ? tamilMonth : ("-" + tamilMonth); previousTamilMonth = tamilMonth; } if (String.Equals(previousSanskritMonth, sanskritMonth, StringComparison.OrdinalIgnoreCase) == false) { sanskritMonthTitle.Text += ((previousSanskritMonth == null) ? sanskritMonth : ("-" + sanskritMonth.Trim())); previousSanskritMonth = sanskritMonth; } highlight = false; // If its the curent month then highlight the current day if (month == DateTime.Today.Month) { if (day == DateTime.Today.Day) { // Highlight today highlight = true; } } else if (day == 1) { // Highlight the first day of some other month highlight = true; } if (highlight) { currentDateItem.HighlightBorder(true); ShowDetail(month, day, item); _currentHighlightedDateItem = currentDateItem; } if (col == (numCols - 1)) { row++; if (row == numRows) { row = 1; // Reset it back to the first row. Provides a foldable calender } } } catch (ArgumentOutOfRangeException) { } } }