Ejemplo n.º 1
0
        public MainPage(IServiceProvider provider
                        , ILogger <MainPage> logger
                        , DocumentViewModel <StorageFile, IRandomAccessStream> viewModel
                        , QuickPadCommands <StorageFile, IRandomAccessStream> command
                        , IVisualThemeSelector vts)
        {
            Provider   = provider;
            VtSelector = vts;
            Logger     = logger;
            Commands   = command;

            Clipboard.ContentChanged += Clipboard_ContentChanged;

            GotFocus += OnGotFocus;

            Initialize?.Invoke(this, Commands, App);

            this.InitializeComponent();

            var rtfOptions = provider.GetService <RtfDocumentOptions>();

            rtfOptions.Document  = RichEditBox.Document;
            rtfOptions.Logger    = provider.GetService <ILogger <RtfDocument> >();
            rtfOptions.ViewModel = viewModel;

            var textOptions = provider.GetService <TextDocumentOptions>();

            textOptions.Document  = TextBox;
            textOptions.Logger    = provider.GetService <ILogger <TextDocument> >();
            textOptions.ViewModel = viewModel;

            CreateNewDocument?.Invoke(this);


            DataContext = ViewModel = viewModel;

            Loaded   += OnLoaded;
            Unloaded += OnUnloaded;

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

            var tBar = ApplicationView.GetForCurrentView().TitleBar;

            tBar.ButtonBackgroundColor         = Colors.Transparent;
            tBar.ButtonInactiveBackgroundColor = Colors.Transparent;


            Settings.ExitApplication = ExitApp;

            ViewModel.PropertyChanged += ViewModel_PropertyChanged;

            Settings.PropertyChanged += Settings_PropertyChanged;

            ViewModel.SetScale += ViewModel_SetScale;

            SystemNavigationManagerPreview.GetForCurrentView().CloseRequested += this.OnCloseRequest;

            var currentView = SystemNavigationManager.GetForCurrentView();

            currentView.BackRequested += CurrentView_BackRequested;

            commandBar.SetFontName += CommandBarOnSetFontName;
            commandBar.SetFontSize += CommandBarOnSetFontSize;

            if (SystemInformation.TotalLaunchCount == 3)
            {
                var(success, dialog) = provider.GetService <DialogManager>().RequestDialog <AskForReviewDialog>();

                if (!success)
                {
                    return;
                }

                _ = dialog.ShowAsync();
            }

            _initialized = true;
        }