Exemplo n.º 1
0
        private FrameworkElement GetCourseElement(Course course, int time, int day = -1)
        {
            var textBlock = new TextBlock();

            textBlock.Text = course.Name;
            //for (int i = 0, count = course.ClassRooms.Count; i < count; i++)
            //textBlock.Text += (i == 0 ? "\n" : "") + course.ClassRooms[i] + (i < count - 1 ? "、" : "");

            textBlock.TextAlignment     = TextAlignment.Center;
            textBlock.TextWrapping      = TextWrapping.Wrap;
            textBlock.FontSize          = 16;
            textBlock.VerticalAlignment = VerticalAlignment.Center;

            Border border = new Border();

            border.MinHeight = 50;
            border.Child     = textBlock;
            border.Tapped   += async(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) =>
            {
                string content = "";

                if (course.ClassRooms.Count > 0)
                {
                    foreach (string classRoom in course.ClassRooms)
                    {
                        content += classRoom + " ";
                    }
                    content += "\n";
                }

                string timeString = Course.GetTimeString(time);

                if (timeString != null)
                {
                    content += timeString + "\n";
                }

                content += string.Format("學分: {0} 時數: {1}\n", course.Credit, course.Hours);

                if (course.Teachers.Count > 0)
                {
                    foreach (string teacher in course.Teachers)
                    {
                        content += teacher + " ";
                    }
                    content += "\n";
                }

                if (!string.IsNullOrWhiteSpace(course.Note))
                {
                    content += course.Note;
                }

                var dialog = new MessageDialog(content, course.Name);
                if (!(string.IsNullOrWhiteSpace(course.IdForSelect) || course.IdForSelect == "0"))
                {
                    dialog.Commands.Add(new UICommand("詳細資料", (command) =>
                    {
                        Frame.Navigate(typeof(CourseDetailPage), course.IdForSelect);
                    }));
                }
                dialog.Commands.Add(new UICommand("關閉"));

                //Send GA Event
                App.Current.GATracker.SendEvent("Other", "Tap on Course", null, 0);

                await dialog.ShowAsync();
            };

            Brush backColor, hoverColor;

            if (DateTime.Today.DayOfWeek == (DayOfWeek)(day + 1 % 7))
            {
                backColor  = new SolidColorBrush(Color.FromArgb(255, 209, 52, 56));
                hoverColor = new SolidColorBrush(Color.FromArgb(255, 180, 52, 56));
            }
            else
            {
                backColor  = new SolidColorBrush(Color.FromArgb(128, 128, 128, 128));
                hoverColor = new SolidColorBrush(Color.FromArgb(255, 128, 128, 128));
            }

            border.Background = backColor;
            border.Padding    = new Thickness(5);
            border.Margin     = new Thickness(1);

            border.PointerEntered += (sender, e) =>
            {
                border.Background = hoverColor;
            };

            border.PointerExited += (sender, e) =>
            {
                border.Background = backColor;
            };

            return(border);
        }
Exemplo n.º 2
0
        private FrameworkElement GetCourseElement(Course course, int time, int day = -1)
        {
            var textBlock = new TextBlock();

            textBlock.Text              = course.Name;
            textBlock.TextAlignment     = TextAlignment.Center;
            textBlock.TextWrapping      = TextWrapping.Wrap;
            textBlock.FontSize          = 16;
            textBlock.VerticalAlignment = VerticalAlignment.Center;

            Border border = new Border();

            border.Child   = textBlock;
            border.Tapped += async(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) =>
            {
                //Send GA Event
                App.Current.GATracker.SendEvent("Other", "Tap on Course", null, 0);

                string content = "";

                if (course.ClassRooms.Count > 0)
                {
                    foreach (string classRoom in course.ClassRooms)
                    {
                        content += classRoom + " ";
                    }
                    content += "\n";
                }

                if (course.Teachers.Count > 0)
                {
                    foreach (string teacher in course.Teachers)
                    {
                        content += teacher + " ";
                    }
                    content += "\n";
                }

                string timeString = Course.GetTimeString(time);

                if (timeString != null)
                {
                    content += timeString + "\n";
                }

                if (!string.IsNullOrWhiteSpace(course.Note))
                {
                    content += course.Note;
                }

                await new MessageDialog(content, course.Name).ShowAsync();
            };

            Brush backColor;

            if (DateTime.Today.DayOfWeek == (DayOfWeek)(day + 1 % 7))
            {
                backColor = Application.Current.Resources["PhoneAccentBrush"] as Brush;
            }
            else
            {
                backColor = new SolidColorBrush(Color.FromArgb(128, 128, 128, 128));
            }

            border.Background = backColor;
            border.Padding    = new Thickness(5);
            border.Margin     = new Thickness(1);

            return(border);
        }