Exemplo n.º 1
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            Website currentWebsite = WebsiteDataSource.GetTempSite();
            Uri     uri            = currentWebsite.URL;
            string  Name           = currentWebsite.Name;

            WebsiteDataSource.AddNewAsync(Name, uri);
            PopulateNavItems();
        }
Exemplo n.º 2
0
        public async Task ActivateAsync(object activationArgs)
        {
            long iD = -1;

            if (IsInteractive(activationArgs))
            {
                if (((IActivatedEventArgs)activationArgs).Kind == ActivationKind.Protocol)
                {
                    var    targetUrl = Uri.UnescapeDataString(((ProtocolActivatedEventArgs)activationArgs).Uri.Query.Substring(1));
                    Uri    uri       = new Uri(targetUrl);
                    string Name      = uri.Host;
                    iD = await WebsiteDataSource.AddNewAsync(Name, uri);
                }

                // Initialize things like registering background task before the app is loaded
                await InitializeAsync();


                // Do not repeat app initialization when the Window already has content,
                // just ensure that the window is active
                if (Window.Current.Content == null)
                {
                    // Create a Frame to act as the navigation context and navigate to the first page
                    Window.Current.Content = _shell;
                    NavigationService.Frame.NavigationFailed += (sender, e) =>
                    {
                        throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
                    };
                    NavigationService.Frame.Navigated += OnFrameNavigated;
                    if (SystemNavigationManager.GetForCurrentView() != null)
                    {
                        SystemNavigationManager.GetForCurrentView().BackRequested += OnAppViewBackButtonRequested;
                    }
                }
            }

            var activationHandler = GetActivationHandlers()
                                    .FirstOrDefault(h => h.CanHandle(activationArgs));

            if (activationHandler != null)
            {
                await activationHandler.HandleAsync(activationArgs);
            }

            if (IsInteractive(activationArgs))
            {
                var defaultHandler = new DefaultLaunchActivationHandler(_defaultNavItem);
                if (defaultHandler.CanHandle(activationArgs))
                {
                    await defaultHandler.HandleAsync(activationArgs);
                }
                else
                {
                    var protocolHandler = new ProtocolActivationHandler(_defaultNavItem, iD);
                    if (protocolHandler.CanHandle(activationArgs))
                    {
                        await protocolHandler.HandleAsync(activationArgs);
                    }
                }

                // Ensure the current window is active
                Window.Current.Activate();

                // Tasks after activation
                await StartupAsync();

                if (iD != -1) //If the app has been launched via protocol
                {
                    await((Views.WebViewPage)NavigationService.Frame.Content).EnterMiniView();
                }
            }
        }