Пример #1
0
        private static async Task<FrameworkElement> LoadElementAsync(string templatePath, TileModel model, Border host)
        {
            var templateFile = await Package.Current.InstalledLocation.GetFileAsync(templatePath);
            var template = await FileIO.ReadTextAsync(templateFile);
            var element = (Border)XamlReader.Load(template);
            element.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
            element.DataContext = model;

            if (host != null)
            {
                host.Child = element;
            }

            return element;
        }
Пример #2
0
        public static async Task<TileModel> BuildTileModelAsync(TileSettings settings)
        {
            var model = new TileModel();

            var now = DateTimeOffset.Now;

            var appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadOnly);
            var appointments = await appointmentStore.FindAppointmentsAsync(now, TimeSpan.FromDays(settings.DayCount));

            var appointmentFilter = CreateAppointmentFilter(settings);

            var filteredAppoinments = appointments.OrderBy(a => a.StartTime).Where(appointmentFilter).Take(settings.AppointmentCount).ToArray();

            if (filteredAppoinments.Length > 0)
            {
                var appointmentText = GetAppointmentText(filteredAppoinments[0], settings);
                model.Appointment1Name = appointmentText.Item1;
                model.Appointment1DateTime = appointmentText.Item2;
            }

            if (filteredAppoinments.Length > 1)
            {
                var appointmentText = GetAppointmentText(filteredAppoinments[1], settings);
                model.Appointment2Name = appointmentText.Item1;
                model.Appointment2DateTime = appointmentText.Item2;
            }

            if (filteredAppoinments.Length > 2)
            {
                var appointmentText = GetAppointmentText(filteredAppoinments[2], settings);
                model.Appointment3Name = appointmentText.Item1;
                model.Appointment3DateTime = appointmentText.Item2;
            }

            model.Day = now.Day.ToString();
            model.DayOfWeek = DateTimeFormatInfo.CurrentInfo.AbbreviatedDayNames[(int)now.DayOfWeek];

            return model;
        }
Пример #3
0
 public static async Task GenerateWideTileImageFileAsync(TileModel model, Border host)
 {
     var element = await LoadElementAsync(Constants.WideTileTemplateFilePath, model, host);
     await GenerateImageFileAsync(Constants.WideTileImageFileName, element, new Size(310, 150));
 }