private async void AddPrivateEvent(DateTime date, String eventText, bool newEvent, PrivateEvent pEvent)
        {
            if (newEvent && _privateEvents.Contains(date, eventText))
            {
                Windows.UI.Popups.MessageDialog md = new Windows.UI.Popups.MessageDialog("Event  name already exists");
                await md.ShowAsync();

                return;
            }

            App         app       = (App)Application.Current;
            ListBoxItem item      = new ListBoxItem();
            TextBlock   textBlock = new TextBlock();

            textBlock.Text = eventText;
            item.Content   = textBlock;
            PersonalEventList.Items.Add(item);
            PersonalEventListScroller.Visibility = Visibility.Visible;
            Separator.BorderThickness            = new Thickness(0, 5, 0, 0);
            _personalEventList.Add(item);
            if (newEvent)
            {
                Debug.Assert(pEvent == null);
                pEvent = new PrivateEvent(date.ToString("d"), eventText);
                _privateEvents._privateEventList.Add(pEvent);
                _currentHighlightedDateItem.SetPrivateEvent(pEvent._eventText);
            }
            item.Tag = pEvent;
        }
        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)
                {
                }
            }
        }
        private async void AddPrivateEvent(DateTime date, String eventText, bool newEvent, PrivateEvent pEvent)
        {

            if (newEvent && _privateEvents.Contains(date, eventText))
            {
                Windows.UI.Popups.MessageDialog md = new Windows.UI.Popups.MessageDialog("Event  name already exists");
                await md.ShowAsync();
                return;
            }

            App app = (App)Application.Current;
            ListBoxItem item = new ListBoxItem();
            TextBlock textBlock = new TextBlock();
            textBlock.Text = eventText;
            item.Content = textBlock;
            PersonalEventList.Items.Add(item);
            PersonalEventListScroller.Visibility = Visibility.Visible;
            Separator.BorderThickness = new Thickness(0, 5, 0, 0);
            _personalEventList.Add(item);
            if (newEvent)
            {
                Debug.Assert(pEvent == null);
                pEvent = new PrivateEvent(date.ToString("d"), eventText);
                _privateEvents._privateEventList.Add(pEvent);
                _currentHighlightedDateItem.SetPrivateEvent(pEvent._eventText);
            }
            item.Tag = pEvent;
        }