protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            DaySlot slot = item as DaySlot;

            if (slot != null)
            {
                if (!slot.IsAdjacent && slot.DayOfWeek == DayOfWeek.Saturday)
                {
                    // set color for Saturday
                    ((Control)container).Foreground = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 0, 90, 255));
                }
                if (!slot.IsAdjacent && Holidays.ContainsKey(slot.Date))
                {
                    Holiday holiday = Holidays[slot.Date];
                    slot.Tag = holiday;
                    return(Resources["Holiday"] as DataTemplate);
                }
                if (slot.Date == DateTime.Today)
                {
                    // use TodayBrush for border
                    ((Control)container).BorderBrush = ((Control)container).Background;
                    // clear background
                    ((Control)container).Background = new SolidColorBrush(Windows.UI.Colors.Transparent);
                    return((slot.IsBolded ? Resources["TodayBoldedDay"] : Resources["TodayUnboldedDay"]) as DataTemplate);
                }
            }

            // the base class will select custom DataTemplate, defined in the DaySlotTemplateSelector.Resources collection (see MainPage.xaml file)
            return(base.SelectTemplateCore(item, container));
        }
Beispiel #2
0
        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            DaySlot slot = item as DaySlot;

            if (slot != null && !slot.IsAdjacent && slot.DayOfWeek == DayOfWeek.Saturday)
            {
                // set color for Saturday
                ((Control)container).Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 191, 255));
            }
            // the base class will select custom DataTemplate, defined in the DaySlotTemplateSelector.Resources collection (see MainPage.xaml file)
            return(base.SelectTemplateCore(item, container));
        }
Beispiel #3
0
        /// <summary>
        /// Draws horizontal borders
        /// </summary>
        /// <param name="g"></param>
        /// <param name="sliceStart"></param>
        /// <param name="sliceEnd"></param>
        /// <param name="dayStart"></param>
        /// <param name="dayEnd"></param>
        /// <param name="daySlots"></param>
        private void DrawHorizontalBorders(Graphics g,
            int sliceStart, int sliceEnd, int dayStart, int dayEnd, DaySlot[,] daySlots)
        {
            if (CalendarView.HasViewDisplayCustomizations == true)
            {
                int n = MinutesPerHour / TimeSlotDuration;

                Color hourBorderColor = _ViewColor.GetColor((int)eCalendarWeekDayPart.DayHourBorder);
                Color halfHourBorderColor = _ViewColor.GetColor((int)eCalendarWeekDayPart.DayHalfHourBorder);

                for (int i = dayStart; i <= dayEnd; i++)
                {
                    for (int j = sliceStart; j <= sliceEnd; j++)
                    {
                        DaySlot daySlot = daySlots[i - dayStart, j - sliceStart];

                        Rectangle r = daySlot.Bounds;
                        DaySlotAppearance dsa = daySlot.Appearance;

                        Point pt1 = r.Location;
                        Point pt2 = new Point(r.Right - 1, r.Y);

                        if (dsa != null && daySlot.Selected == false)
                        {
                            using (Pen pen = new Pen(j % n == 0 ? dsa.HourBorderColor : dsa.HalfHourBorderColor))
                                g.DrawLine(pen, pt1, pt2);

                            continue;
                        }

                        using (Pen pen = new Pen(j % n == 0 ? hourBorderColor : halfHourBorderColor))
                            g.DrawLine(pen, pt1, pt2);
                    }
                }
            }
            else
            {
                using (Pen pen1 = new Pen(
                    _ViewColor.GetColor((int) eCalendarWeekDayPart.DayHourBorder)))
                {
                    using (Pen pen2 = new Pen(
                        _ViewColor.GetColor((int) eCalendarWeekDayPart.DayHalfHourBorder)))
                    {
                        Point pt1 = new Point(_DayColumns[dayStart].Bounds.X, 0);
                        Point pt2 = new Point(_DayColumns[dayEnd].Bounds.Right - 1, 0);

                        int n = MinutesPerHour/TimeSlotDuration;

                        for (int i = sliceStart; i <= sliceEnd; i++)
                        {
                            Rectangle r = GetSliceRect(0, i);

                            pt1.Y = pt2.Y = r.Y;

                            g.DrawLine((i%n) == 0 ? pen1 : pen2, pt1, pt2);
                        }
                    }
                }
            }
        }
        private async void calendar_DoubleTapped(object sender, RoutedEventArgs e)
        {
            if (_calTask != null)
            {
                // if there is already opened task, cancel it first
                _calTask.Cancel();
                _calTask.Close();
                _calTask = null;
            }
            // show the list of appointments for the bolded day
            FrameworkElement fel = e.OriginalSource as FrameworkElement;

            if (fel != null)
            {
                DaySlot slot = fel.DataContext as DaySlot;
                if (slot != null)
                {
                    DateTime date    = slot.Date;
                    string   message = date.ToString();
                    if (slot.DataSource == null || slot.DataSource.Count == 0)
                    {
                        if (UseAppointmentManager)
                        {
                            // create new appointment and fill initial properties
                            Windows.ApplicationModel.Appointments.Appointment app = new Windows.ApplicationModel.Appointments.Appointment();
                            app.StartTime = date;
                            app.AllDay    = true;
                            app.Subject   = Strings.DeviceAppointmentSubject;
                            // Show the Appointments provider Add Appointment UI, to enable the user to add an appointment.
                            // The returned id can be used later to edit or remove existent appointment.
                            _calTask = AppointmentManager.ShowEditNewAppointmentAsync(app);
                            string id = await _calTask;
                            Refresh(calendar.DisplayDate);
                            _calTask = null;
                            return;
                        }
                        else
                        {
                            if (!Device.IsWindowsPhoneDevice())
                            {
                                DataTemplate boldedDaySlotTemplate = this.Resources["BoldedDaySlotTemplate"] as DataTemplate;
                                calendar.BoldedDaySlotTemplate = boldedDaySlotTemplate;
                                Appointment app = new Appointment();
                                app.Start    = calendar.SelectedDate;
                                app.Duration = TimeSpan.FromDays(1);
                                app.Subject  = Strings.AppointmentSubject + " " + app.Start.ToString();
                                _appointments.Add(app);
                                calendar.DataSource = _appointments;
                                return;
                            }
                            else
                            {
                                message += "\r\n" + Strings.Message;
                            }
                        }
                    }
                    else
                    {
                        if (!UseAppointmentManager)
                        {
                            foreach (Appointment app in slot.DataSource)
                            {
                                message += "\r\n" + app.Subject;
                            }
                        }
                        else
                        {
                            foreach (Windows.ApplicationModel.Appointments.Appointment app in slot.DataSource)
                            {
                                message += "\r\n" + app.Subject;
                            }
                        }
                        var dialog = new MessageDialog(message);
                        dialog.ShowAsync();
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Draws time slice borders
        /// </summary>
        /// <param name="g">Graphics</param>
        /// <param name="sliceStart">Start slice</param>
        /// <param name="sliceEnd">End slice</param>
        /// <param name="dayStart">Day start</param>
        /// <param name="dayEnd">Day end</param>
        /// <param name="daySlots"></param>
        private void DrawBorders(Graphics g,
            int sliceStart, int sliceEnd, int dayStart, int dayEnd, DaySlot[,] daySlots)
        {
            // Draw the horizontal and vertical borders, and
            // the current "Now" border

            DrawHorizontalBorders(g, sliceStart, sliceEnd, dayStart, dayEnd, daySlots);
            DrawVerticalBorders(g, sliceStart, sliceEnd, dayStart, dayEnd);

            if (CalendarView.HighlightCurrentDay == true)
                DrawNowBorder(g, dayStart, dayEnd);
        }
Beispiel #6
0
        /// <summary>
        /// Initiates DaySlot drawing
        /// </summary>
        /// <param name="g"></param>
        /// <param name="sliceStart"></param>
        /// <param name="sliceEnd"></param>
        /// <param name="dayStart"></param>
        /// <param name="dayEnd"></param>
        /// <param name="daySlots"></param>
        /// <param name="onTop">On top of borders</param>
        private void DrawDaySlot(Graphics g, int sliceStart,
            int sliceEnd, int dayStart, int dayEnd, DaySlot[,] daySlots, bool onTop)
        {
            List<DaySlotAppearance> dsaList = null;
            Rectangle dRect = Rectangle.Empty;

            for (int i = dayStart; i <= dayEnd; i++)
            {
                DaySlot lastDaySlot = null;

                for (int j = sliceStart; j <= sliceEnd; j++)
                {
                    DaySlot daySlot = daySlots[i - dayStart, j - sliceStart];

                    Rectangle r = daySlot.Bounds;
                    DaySlotAppearance dsa = daySlot.Appearance;

                    if (lastDaySlot != null &&
                        (lastDaySlot.Appearance != dsa || lastDaySlot.Selected != daySlot.Selected))
                    {
                        FlushDaySlotText(g, i, dsaList, ref dRect, lastDaySlot.Selected);
                    }

                    lastDaySlot = daySlot;

                    if (dsa != null)
                    {
                        if (dsa.OnTop == onTop)
                        {
                           if (daySlot.Selected == true)
                           {
                               if (dsa.ShowTextWhenSelected == true)
                                   dRect = dRect.IsEmpty ? r : Rectangle.Union(dRect, r);
                           }
                           else
                           {
                               dRect = dRect.IsEmpty ? r : Rectangle.Union(dRect, r);
                           }

                           if (dsaList == null)
                                dsaList = new List<DaySlotAppearance>();

                            if (dsaList.Contains(dsa) == false)
                                dsaList.Add(dsa);
                        }

                        continue;
                    }
                }

                if (lastDaySlot != null)
                    FlushDaySlotText(g, i, dsaList, ref dRect, lastDaySlot.Selected);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Gets the background content brush
        /// for the given time slice
        /// </summary>
        /// <param name="daySlot"></param>
        /// <param name="col">Column index</param>
        /// <param name="slice">Time slice</param>
        /// <returns>Background brush</returns>
        private Brush GetContentBrush(DaySlot daySlot, int col, int slice)
        {
            int start = (StartSlice + slice) * TimeSlotDuration;

            if (slice < NumberOfActiveSlices)
            {
                if (daySlot.Selected == true)
                    return (SelectedBrush);

                WorkTime wkStart = new
                    WorkTime(start / MinutesPerHour, start % MinutesPerHour);

                if (_DayColumns[col].IsWorkTime(wkStart) == true)
                    return (WorkBrush);

                if (_DayColumns[col].IsBusyTime(wkStart) == true)
                    return (BusyBrush);
            }
            else
            {
                return (AllDayBrush);
            }

            return (OffWorkBrush);
        }
Beispiel #8
0
        /// <summary>
        /// Time slice content drawing
        /// </summary>
        /// <param name="g">Graphics</param>
        /// <param name="sliceStart">Start slice</param>
        /// <param name="sliceEnd">End slice</param>
        /// <param name="dayStart">Day start</param>
        /// <param name="dayEnd">Day end</param>
        /// <param name="daySlots"></param>
        private void DrawContent(Graphics g,
            int sliceStart, int sliceEnd, int dayStart, int dayEnd, DaySlot[,] daySlots)
        {
            // Loop through each day in each week, displaying
            // the associated day content

            for (int i = dayStart; i <= dayEnd; i++)
            {
                for (int j = sliceStart; j <= sliceEnd; j++)
                {
                    DaySlot daySlot = daySlots[i - dayStart, j - sliceStart];
                    DaySlotAppearance dsa = daySlot.Appearance;

                    if (dsa != null && daySlot.Selected == false)
                    {
                        using (Brush br = new SolidBrush(dsa.BackColor))
                            g.FillRectangle(br, daySlot.Bounds);

                        continue;
                    }

                    g.FillRectangle(GetContentBrush(daySlot, i, j), daySlot.Bounds);
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// Gets the array of DaySlot information
        /// </summary>
        /// <param name="sliceStart"></param>
        /// <param name="sliceEnd"></param>
        /// <param name="dayStart"></param>
        /// <param name="dayEnd"></param>
        /// <returns>array of DaySlots</returns>
        private DaySlot[,] GetDaySlots(int sliceStart, int sliceEnd, int dayStart, int dayEnd)
        {
            DaySlot[,] daySlots = new DaySlot[dayEnd - dayStart + 1, sliceEnd - sliceStart + 1];

            for (int i = dayStart; i <= dayEnd; i++)
            {
                for (int j = sliceStart; j <= sliceEnd; j++)
                {
                    DaySlot daySlot = new DaySlot();

                    daySlots[i - dayStart, j - sliceStart] = daySlot;

                    daySlot.Bounds = GetSliceRect(i, j);
                    daySlot.Selected = SliceIsSelected(i, j);

                    if (j <= sliceEnd &&
                        CalendarView.HasViewDisplayCustomizations == true)
                    {
                        int start = ((StartSlice + j) * TimeSlotDuration) % 1440;
                        int end = Math.Min(start + TimeSlotDuration, 1439);

                        WorkTime wkStart = new WorkTime(start / MinutesPerHour, start % MinutesPerHour);
                        WorkTime wkEnd = new WorkTime(end / MinutesPerHour, end % MinutesPerHour);

                        daySlot.Appearance = CalendarView.ViewDisplayCustomizations.GetDaySlotAppearance(
                            OwnerKey, _DayColumns[i].Date, wkStart, wkEnd);
                    }
                }
            }

            return (daySlots);
        }