Example #1
0
        public static Canvas GetCalendarCanvas(double width, double height, LockscreenData data)
        {
            Canvas calendarCanvas = new Canvas();

            calendarCanvas.Width  = width;
            calendarCanvas.Height = height;
            SolidColorBrush phoneInactiveBrush        = (SolidColorBrush)Application.Current.Resources["PhoneInactiveBrush"];
            SolidColorBrush phoneSemitransparentBrush = (SolidColorBrush)Application.Current.Resources["PhoneSemitransparentBrush"];

            int rowNum = -1, colNum = 0;;

            for (int i = 0; i < data.DayList.Count; i++)
            {
                if (i % 7 == 0)
                {
                    rowNum++;
                    colNum = 0;
                }
                ChameleonLib.Api.Calendar.Model.Day day = data.DayList[i];

                Canvas dayPanel = new Canvas()
                {
                    Width  = calendarCanvas.Width / 7,
                    Height = calendarCanvas.Height / 7,
                };

                TextBlock dayTxt = new TextBlock()
                {
                    Text       = day.DayName,
                    FontSize   = day.FontSize * data.FontRatio,
                    Foreground = day.ForegroundBrush.Color == phoneInactiveBrush.Color ? phoneSemitransparentBrush : day.ForegroundBrush,
                    FontWeight = data.FontWeight
                };

                if (day.DateTime.ToLongDateString() == DateTime.Today.ToLongDateString())
                {
                    Ellipse ellipse = new Ellipse()
                    {
                        Width  = dayTxt.ActualHeight * 1.08,
                        Height = dayTxt.ActualHeight * 1.08,
                        Fill   = day.BackgroundBrush,
                    };

                    dayPanel.Children.Add(ellipse);
                    Canvas.SetLeft(ellipse, (dayPanel.Width - ellipse.Width) / 2);
                    Canvas.SetTop(ellipse, (dayPanel.Height - ellipse.Width) / 2 - 0.5);
                }

                if (data.DayList[i].AppointmentList != null && data.DayList[i].AppointmentList.Count > 0)
                {
                    TextBlock appCnt = new TextBlock()
                    {
                        FontSize   = day.FontSize * data.FontRatio * 0.5,
                        Text       = data.DayList[i].AppointmentList.Count.ToString(),
                        Foreground = day.DateTime.ToLongDateString() == DateTime.Now.ToLongDateString() ? day.BackgroundBrush : day.ForegroundBrush,
                        FontWeight = day.ForegroundBrush.Color == phoneInactiveBrush.Color ? FontWeights.Normal : FontWeights.Bold
                    };
                    dayPanel.Children.Add(appCnt);
                    Canvas.SetLeft(appCnt, (dayPanel.Width - appCnt.ActualWidth - 5));
                    Canvas.SetTop(appCnt, -appCnt.ActualHeight / 3);
                }

                dayPanel.Margin = new Thickness((colNum++) * dayPanel.Width, rowNum * dayPanel.Height, 0, 0);

                dayPanel.Children.Add(dayTxt);
                Canvas.SetLeft(dayTxt, (dayPanel.Width - dayTxt.ActualWidth) / 2);
                Canvas.SetTop(dayTxt, (dayPanel.Height - dayTxt.ActualHeight) / 2);
                calendarCanvas.Children.Add(dayPanel);
            }
            return(calendarCanvas);
        }
Example #2
0
        public static Canvas GetCalendarCanvas(LivetileData data)
        {
            Canvas calendarCanvas = new Canvas();

            calendarCanvas.Width  = data.AreaSize.Width;
            calendarCanvas.Height = data.AreaSize.Height;

            int rowNum = -1, colNum = 0;;

            for (int i = 0; i < data.DayList.Count; i++)
            {
                if (i % 7 == 0)
                {
                    rowNum++;
                    colNum = 0;
                }
                ChameleonLib.Api.Calendar.Model.Day day = data.DayList[i];

                Canvas dayPanel = new Canvas()
                {
                    Width  = calendarCanvas.Width / 7 - 1,
                    Height = calendarCanvas.Height / 7 - 1,
                    //Background = day.BackgroundBrush,
                };
                dayPanel.Margin = new Thickness((colNum++) * dayPanel.Width + 1, rowNum * dayPanel.Height, 0, 0);

                TextBlock dayTxt = new TextBlock()
                {
                    Text       = day.DayName,
                    FontSize   = day.FontSize * (day.DateTime.Year == 1 ? 1.1 : 1.2),
                    Foreground = day.ForegroundBrush,
                    FontWeight = data.FontWeight
                };

                if (day.DateTime.ToLongDateString() == DateTime.Today.ToLongDateString())
                {
                    Ellipse ellipse = new Ellipse()
                    {
                        Width  = dayTxt.ActualHeight * 1.08,
                        Height = dayTxt.ActualHeight * 1.08,
                        Fill   = day.BackgroundBrush
                    };

                    dayPanel.Children.Add(ellipse);
                    Canvas.SetLeft(ellipse, (dayPanel.Width - ellipse.Width) / 2);
                    Canvas.SetTop(ellipse, (dayPanel.Height - ellipse.Width) / 2 - 0.5);
                }

                if (data.DayList[i].AppointmentList != null && data.DayList[i].AppointmentList.Count > 0)
                {
                    TextBlock appCnt = new TextBlock()
                    {
                        Text       = data.DayList[i].AppointmentList.Count.ToString(),
                        FontSize   = 13,
                        Foreground = day.DateTime.ToLongDateString() == DateTime.Now.ToLongDateString() ? day.BackgroundBrush : day.ForegroundBrush,
                        FontWeight = FontWeights.ExtraBold
                    };
                    dayPanel.Children.Add(appCnt);
                    Canvas.SetLeft(appCnt, (dayPanel.Width - appCnt.ActualWidth));
                    Canvas.SetTop(appCnt, -appCnt.ActualHeight / 3);
                }

                dayPanel.Children.Add(dayTxt);
                Canvas.SetLeft(dayTxt, (dayPanel.Width - dayTxt.ActualWidth) / 2);
                Canvas.SetTop(dayTxt, (dayPanel.Height - dayTxt.ActualHeight) / 2);
                calendarCanvas.Children.Add(dayPanel);
            }
            return(calendarCanvas);
        }