Пример #1
0
        } = new Setting();                            //Store all app setting here..

        public MainPage()
        {
            InitializeComponent();

            //extent app in to the title bar
            CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
            ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar;

            titleBar.ButtonBackgroundColor         = Colors.Transparent;
            titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;

            //Subscribe to events
            QSetting.afterThemeChanged += UpdateUIAccordingToNewTheme;
            UpdateUIAccordingToNewTheme(QSetting.Theme);
            QSetting.afterFontSizeChanged += UpdateText1FontSize;
            QSetting.afterAutoSaveChanged += UpdateAutoSave;
            //
            CreateItems();
            LoadSettings();
            LoadFonts();

            VersionNumber.Text = string.Format(textResource.GetString("VersionFormat"), Package.Current.Id.Version.Major, Package.Current.Id.Version.Minor, Package.Current.Id.Version.Build, Package.Current.Id.Version.Revision);

            //check if focus is on app or off the app
            Window.Current.CoreWindow.Activated += (sender, args) =>
            {
                if (args.WindowActivationState == Windows.UI.Core.CoreWindowActivationState.Deactivated)
                {
                    CommandBar2.Focus(FocusState.Programmatic); // Set focus off the main content
                }
            };

            //ask user if they want to save before closing the app
            Windows.UI.Core.Preview.SystemNavigationManagerPreview.GetForCurrentView().CloseRequested += async(sender, e) =>
            {
                var deferral = e.GetDeferral();

                if (!Changed)
                {
                    //No change made, either new document or file saved
                    deferral.Complete();
                }

                //close dialogs so the app does not hang
                SaveDialog.Hide();
                Settings.Hide();

                await SaveDialog.ShowAsync();

                if (SaveDialogValue != DialogResult.Cancel)
                {
                    deferral.Complete();
                }

                if (SaveDialogValue == DialogResult.Cancel)
                {
                    e.Handled = true;
                    deferral.Complete();
                }

                SaveDialogValue = DialogResult.None; //reset save dialog
            };

            CheckPushNotifications(); //check for push notifications

            this.Loaded        += MainPage_Loaded;
            this.LayoutUpdated += MainPage_LayoutUpdated;
        }