コード例 #1
0
        /// <summary>
        /// Custom startup so we load our IoC immediately before anything else
        /// </summary>
        /// <param name="e"></param>
        protected override async void OnStartup(StartupEventArgs e)
        {
            // Let the base application do what it needs.
            base.OnStartup(e);

            // Fix FPS.
            Timeline.DesiredFrameRateProperty.OverrideMetadata(
                typeof(Timeline),
                new FrameworkPropertyMetadata {
                DefaultValue = 60
            }
                );

            // Setup the main application
            ApplicationSetupAsync();

            // Set up YAML config file(s).
            IoC.Application.CandyCategories = await YamlHelper.LoadConfigFile($"{AppDomain.CurrentDomain.BaseDirectory}");

            // Pre-cache images.
            foreach (var category in IoC.Application.CandyCategories)
            {
                _cachedImages.Add(new BitmapImage(new Uri(category.ImageUrl), new HttpRequestCachePolicy(new DateTime(10000000))));
                foreach (var type in category.CandyTypes)
                {
                    _cachedImages.Add(new BitmapImage(new Uri(type.ImageUrl), new HttpRequestCachePolicy(new DateTime(10000000))));
                }
            }

            // Setup the application view model.
            IoC.Application.GoToPage(DataModels.ApplicationPage.Categories, new CategoriesViewModel {
                PageLoadAnimation = PageAnimation.None, PageUnloadAnimation = PageAnimation.SlideOutToRight
            });

            // Set up idle timer.
            IdleTimer.Interval = new TimeSpan(0, 0, 1);
            IdleTimer.Tick    += (sender, arg) =>
            {
                // If UI has been idle for 30 seconds.
                if (GetIdleTime() > 30 * 1000)
                {
                    // Go back to main screen.
                    IoC.Application.GoToPage(DataModels.ApplicationPage.Categories);
                    IoC.Application.DarkeningGridOpacity = 0;
                    IoC.Application.PayButtonVisibility  = Visibility.Hidden;
                }
            };
            IdleTimer.Start();
        }