예제 #1
0
        public void Initialize(CoreWindow coreWindow, UIElement inputElement, TouchQueue touchQueue)
        {
            _coreWindow  = coreWindow;
            _inputEvents = new InputEvents(_coreWindow, inputElement, touchQueue);

            _dinfo   = DisplayInformation.GetForCurrentView();
            _appView = ApplicationView.GetForCurrentView();

            // Set a min size that is reasonable knowing someone might try
            // to use some old school resolution like 640x480.
            var minSize = new Windows.Foundation.Size(640 / _dinfo.RawPixelsPerViewPixel, 480 / _dinfo.RawPixelsPerViewPixel);

            _appView.SetPreferredMinSize(minSize);

            _orientation = ToOrientation(_dinfo.CurrentOrientation);
            _dinfo.OrientationChanged += DisplayProperties_OrientationChanged;

            _coreWindow.SizeChanged += Window_SizeChanged;

            _coreWindow.Closed    += Window_Closed;
            _coreWindow.Activated += Window_FocusChanged;

            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
            {
                Windows.Phone.UI.Input.HardwareButtons.BackPressed += this.HardwareButtons_BackPressed;
            }

            SetViewBounds(_appView.VisibleBounds.Width, _appView.VisibleBounds.Height);

            SetCursor(false);
        }
예제 #2
0
        private async void SymbolIcon_Tapped_1(object sender, TappedRoutedEventArgs e)
        {
            Employee        employee = employeeView.DataContext as Employee;
            ApplicationView newView = null;
            await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var frame = new Frame();
                frame.Navigate(typeof(EmployeePage), employee);
                Window.Current.Content = frame;
                Window.Current.Activate();
                newView = ApplicationView.GetForCurrentView();
                newView.SetPreferredMinSize(new Size(200, 200));
                newView.Title = employee.Name;
                newView.SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);
                newView.TitleBar.BackgroundColor = Windows.UI.Colors.Transparent;
            });

            var compactOptions = ViewModePreferences.CreateDefault(ApplicationViewMode.CompactOverlay);

            compactOptions.CustomSize         = new Size(300, 200);
            compactOptions.ViewSizePreference = ViewSizePreference.Custom;
            await ApplicationViewSwitcher.TryShowAsViewModeAsync(newView.Id, ApplicationViewMode.CompactOverlay, compactOptions);

            employeeView.Visibility = Visibility.Collapsed;
        }
        async public Task InitializeAsync(Geopoint center)
        {
            Center = center;
            streetview_map.Center = Center;
            if (streetview_map.IsStreetsideSupported)
            {
                var street_panorama = await StreetsidePanorama.FindNearbyAsync(streetview_map.Center);

                var street_exp = new StreetsideExperience(street_panorama);
                street_exp.OverviewMapVisible   = true;
                streetview_map.CustomExperience = street_exp;
            }
            else
            {
                NotSupported?.Invoke();
            }
            _core_appview.TitleBar.ExtendViewIntoTitleBar = true;


            //size the window
            _appview.SetPreferredMinSize(new Size(500, 400));

            //set background
            _appview.TitleBar.ButtonBackgroundColor         = Colors.Transparent;
            _appview.TitleBar.ButtonForegroundColor         = Colors.White;
            _appview.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
            _appview.TitleBar.ButtonInactiveForegroundColor = Colors.White;

            rect_titlebar.Fill = new SolidColorBrush(TitlebarColor);
            Window.Current.SetTitleBar(rect_titlebar);
        }
예제 #4
0
        public void Initialize(CoreWindow coreWindow, UIElement inputElement, TouchQueue touchQueue)
        {
            _coreWindow   = coreWindow;
            _windowEvents = new InputEvents(_coreWindow, inputElement, touchQueue);

            _dinfo   = DisplayInformation.GetForCurrentView();
            _appView = ApplicationView.GetForCurrentView();

            // Set a min size that is reasonable knowing someone might try
            // to use some old school resolution like 640x480.
            var minSize = new Windows.Foundation.Size(640 / _dinfo.RawPixelsPerViewPixel, 480 / _dinfo.RawPixelsPerViewPixel);

            _appView.SetPreferredMinSize(minSize);

            _orientation = ToOrientation(_dinfo.CurrentOrientation);
            _dinfo.OrientationChanged += DisplayProperties_OrientationChanged;
            _swapChainPanel            = inputElement as SwapChainPanel;

            _swapChainPanel.SizeChanged += SwapChain_SizeChanged;

            _coreWindow.Closed            += Window_Closed;
            _coreWindow.Activated         += Window_FocusChanged;
            _coreWindow.CharacterReceived += Window_CharacterReceived;

            SetViewBounds(_appView.VisibleBounds.Width, _appView.VisibleBounds.Height);

            SetCursor(false);
        }
예제 #5
0
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            ApplicationView view = ApplicationView.GetForCurrentView();

            view.SetPreferredMinSize(new Size(450, 500));
            view.SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);

            if (rootFrame == null)
            {
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Загрузить состояние из ранее приостановленного приложения
                }

                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    rootFrame.Navigate(typeof(MainPage), e.Arguments);
                }

                Window.Current.Activate();
            }
        }
예제 #6
0
        public async Task<bool> TryCreateNewWindowAsync(TabViewViewModel tabView, Size size)
        {
            CoreApplicationView newView = CoreApplication.CreateNewView();

            int newViewId = 0;

            await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                ApplicationView applicationView = ApplicationView.GetForCurrentView();
                applicationView.SetPreferredMinSize(new Size(MinWindowWidth, MinWindowHeight));
                applicationView.TryResizeView(size);

                Frame frame = new Frame();
                frame.Navigate(typeof(AppWindowPage), new TabViewNavigationParameters(tabView));

                Window.Current.Content = frame;

                Window.Current.Activate();

                newViewId = ApplicationView.GetForCurrentView().Id;
            });

            bool success = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);

            return success;
        }
예제 #7
0
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            ApplicationView av = ApplicationView.GetForCurrentView();

            av.SetPreferredMinSize(new Size(300, 800));
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Auto;
            SetDiveRect();
        }
예제 #8
0
        private static void SetMinWindowSizeAndActivate(Frame rootFrame, Size minWindowSize)
        {
            // SetPreferredMinSize should always be called before Window.Activate
            ApplicationView appView = ApplicationView.GetForCurrentView();

            appView.SetPreferredMinSize(minWindowSize);

            // Place the frame in the current Window
            Window.Current.Content = rootFrame;
            Window.Current.Activate();
        }
예제 #9
0
        public static async Task OpenPropertiesWindowAsync(object item, IShellPage associatedInstance)
        {
            if (item == null)
            {
                return;
            }

            if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
            {
                CoreApplicationView newWindow = CoreApplication.CreateNewView();
                ApplicationView     newView   = null;

                await newWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    Frame frame = new Frame();
                    frame.Navigate(typeof(Properties), new PropertiesPageNavigationArguments()
                    {
                        Item = item,
                        AppInstanceArgument = associatedInstance
                    }, new SuppressNavigationTransitionInfo());
                    Window.Current.Content = frame;
                    Window.Current.Activate();

                    newView = ApplicationView.GetForCurrentView();
                    newWindow.TitleBar.ExtendViewIntoTitleBar = true;
                    newView.Title            = "PropertiesTitle".GetLocalized();
                    newView.PersistedStateId = "Properties";
                    newView.SetPreferredMinSize(new Size(400, 500));
                    newView.Consolidated += delegate
                    {
                        Window.Current.Close();
                    };

                    bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newView.Id);
                    if (viewShown && newView != null)
                    {
                        // Set window size again here as sometimes it's not resized in the page Loaded event
                        newView.TryResizeView(new Size(400, 550));
                    }
                });
            }
            else
            {
                var propertiesDialog = new PropertiesDialog();
                propertiesDialog.propertiesFrame.Tag = propertiesDialog;
                propertiesDialog.propertiesFrame.Navigate(typeof(Properties), new PropertiesPageNavigationArguments()
                {
                    Item = item,
                    AppInstanceArgument = associatedInstance
                }, new SuppressNavigationTransitionInfo());
                await propertiesDialog.ShowAsync(ContentDialogPlacement.Popup);
            }
        }
예제 #10
0
        /// <summary>
        /// Вызывается при обычном запуске приложения пользователем.  Будут использоваться другие точки входа,
        /// например, если приложение запускается для открытия конкретного файла.
        /// </summary>
        /// <param name="e">Сведения о запросе и обработке запуска.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.ApplicationView"))
            {
                var titleBar = ApplicationView.GetForCurrentView().TitleBar;
                if (titleBar != null)
                {
                    titleBar.ButtonBackgroundColor = GetSolidColorBrush("#FFFFFFFF").Color;
                }
            }

            ApplicationView appView = ApplicationView.GetForCurrentView();

            appView.SetPreferredMinSize(new Size(500, 500));
            ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    // When the navigation stack isn't restored navigate to the first page,
                    // configuring the new page by passing required information as a navigation
                    // parameter
                    rootFrame.Navigate(typeof(Authorize), e.Arguments);
                }
                // Ensure the current window is active
                Window.Current.Activate();
            }
            //SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
        }
예제 #11
0
        private async void OpenAdvancedProperties()
        {
            if (SecurityProperties == null)
            {
                return;
            }

            if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
            {
                if (propsView == null)
                {
                    var newWindow = CoreApplication.CreateNewView();

                    await newWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                    {
                        Frame frame = new Frame();
                        frame.Navigate(typeof(PropertiesSecurityAdvanced), new PropertiesPageNavigationArguments()
                        {
                            Item = SecurityProperties.Item,
                            AppInstanceArgument = AppInstance
                        }, new SuppressNavigationTransitionInfo());
                        Window.Current.Content = frame;
                        Window.Current.Activate();

                        propsView = ApplicationView.GetForCurrentView();
                        newWindow.TitleBar.ExtendViewIntoTitleBar = true;
                        propsView.Title            = string.Format("SecurityAdvancedPermissionsTitle".GetLocalized(), SecurityProperties.Item.ItemName);
                        propsView.PersistedStateId = "PropertiesSecurity";
                        propsView.SetPreferredMinSize(new Size(400, 500));
                        propsView.Consolidated += PropsView_Consolidated;

                        bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(propsView.Id);
                        if (viewShown && propsView != null)
                        {
                            // Set window size again here as sometimes it's not resized in the page Loaded event
                            propsView.TryResizeView(new Size(850, 550));
                        }
                    });
                }
                await ApplicationViewSwitcher.SwitchAsync(propsView.Id);
            }
            else
            {
                // Unsupported
            }
        }
예제 #12
0
        protected internal override void Initialize(GameContext windowContext)
        {
            swapChainPanel = (windowContext as GameContextUWPXaml)?.Control;
            coreWindow     = (windowContext as GameContextUWPCoreWindow)?.Control;

            if (swapChainPanel != null)
            {
                resizeTimer = new DispatcherTimer {
                    Interval = TimeSpan.FromMilliseconds(100)
                };
                resizeTimer.Tick += ResizeTimerOnTick;

                coreWindow   = CoreWindow.GetForCurrentThread();
                windowHandle = new WindowHandle(AppContextType.UWPXaml, swapChainPanel, IntPtr.Zero);
            }
            else if (coreWindow != null)
            {
                coreWindow.SizeChanged += ResizeOnWindowChange;
                windowHandle            = new WindowHandle(AppContextType.UWPCoreWindow, coreWindow, IntPtr.Zero);
            }
            else
            {
                Debug.Assert(swapChainPanel == null && coreWindow == null, "GameContext was neither UWPXaml nor UWPCoreWindow");
            }

            applicationView = ApplicationView.GetForCurrentView();
            if (applicationView != null && windowContext.RequestedWidth != 0 && windowContext.RequestedHeight != 0)
            {
                applicationView.SetPreferredMinSize(new Size(windowContext.RequestedWidth, windowContext.RequestedHeight));
                canResize = applicationView.TryResizeView(new Size(windowContext.RequestedWidth, windowContext.RequestedHeight));
            }

            requiredRatio = windowContext.RequestedWidth / (double)windowContext.RequestedHeight;

            if (swapChainPanel != null)
            {
                swapChainPanel.SizeChanged             += swapChainPanel_SizeChanged;
                swapChainPanel.CompositionScaleChanged += swapChainPanel_CompositionScaleChanged;
            }

            coreWindow.SizeChanged += CurrentWindowOnSizeChanged;

            visible = coreWindow.Visible;
            coreWindow.VisibilityChanged += CurrentWindowOnVisibilityChanged;
            coreWindow.Activated         += CurrentWindowOnActivated;
        }
예제 #13
0
        protected override void Initialize(GameContext <SwapChainPanel> windowContext)
        {
            Debug.Assert(windowContext is GameContextUWP, "By design only one descendant of GameContext<SwapChainPanel>");
            swapChainPanel = windowContext.Control;
            windowHandle   = new WindowHandle(AppContextType.UWP, swapChainPanel, IntPtr.Zero);

            applicationView = ApplicationView.GetForCurrentView();
            if (applicationView != null && windowContext.RequestedWidth != 0 && windowContext.RequestedHeight != 0)
            {
                applicationView.SetPreferredMinSize(new Size(windowContext.RequestedWidth, windowContext.RequestedHeight));
                canResize = applicationView.TryResizeView(new Size(windowContext.RequestedWidth, windowContext.RequestedHeight));
            }

            requiredRatio = windowContext.RequestedWidth / (double)windowContext.RequestedHeight;

            swapChainPanel.SizeChanged             += swapChainPanel_SizeChanged;
            swapChainPanel.CompositionScaleChanged += swapChainPanel_CompositionScaleChanged;
            coreWindow.SizeChanged += CurrentWindowOnSizeChanged;
        }
예제 #14
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            ApplicationView view = ApplicationView.GetForCurrentView();

            ApplicationView.PreferredLaunchViewSize      = new Size(328, 100);
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
            view.SetPreferredMinSize(new Size(328, 100));

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    // When the navigation stack isn't restored navigate to the first page,
                    // configuring the new page by passing required information as a navigation
                    // parameter
                    rootFrame.Navigate(typeof(MainPage), e.Arguments);
                }
                // Ensure the current window is active
                Window.Current.Activate();
            }
        }
예제 #15
0
        private void ScreenSize_Loaded(object sender, RoutedEventArgs e)
        {
            // Window.Current.Bounds - 当前窗口的大小(单位是有效像素,没有特别说明就都是有效像素)
            //     注:窗口大小不包括标题栏,标题栏属于系统级 UI
            lblMsg.Text = string.Format("window size: {0} * {1}", Window.Current.Bounds.Width, Window.Current.Bounds.Height);

            ApplicationView applicationView = ApplicationView.GetForCurrentView();

            // SetPreferredMinSize(Size minSize) - 指定窗口允许的最小尺寸(最小:192×48,最大:500×500)
            applicationView.SetPreferredMinSize(new Size(200, 200));

            // PreferredLaunchViewSize - 窗口启动时的初始尺寸
            // 若要使 PreferredLaunchViewSize 设置有效,需要将 ApplicationView.PreferredLaunchWindowingMode 设置为 ApplicationViewWindowingMode.PreferredLaunchViewSize
            ApplicationView.PreferredLaunchViewSize      = new Size(800, 480);
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;

            /*
             * ApplicationView.PreferredLaunchWindowingMode - 窗口的启动模式
             *     Auto - 系统自动调整
             *     PreferredLaunchViewSize - 由 ApplicationView.PreferredLaunchViewSize 决定
             *     FullScreen - 全屏启动
             */
        }
예제 #16
0
        public GameWindowUwp(Game game) : base(game)
        {
            GameContext gameContext = game.Context;

            switch (gameContext)
            {
            case GameContextCoreWindow coreWindowContext:
                coreWindow = coreWindowContext.Control;

                windowHandle = new WindowHandle(AppContextType.CoreWindow, coreWindow, IntPtr.Zero);
                break;

            case GameContextXaml xamlContext:
                coreWindow     = CoreWindow.GetForCurrentThread();
                swapChainPanel = xamlContext.Control;

                windowHandle = new WindowHandle(AppContextType.Xaml, swapChainPanel, IntPtr.Zero);

                swapChainPanel.SizeChanged             += SwapChainPanel_SizeChanged;
                swapChainPanel.CompositionScaleChanged += SwapChainPanel_CompositionScaleChanged;
                break;

            default:
                throw new ArgumentException();
            }

            coreWindow.SizeChanged += CoreWindow_SizeChanged;

            applicationView = ApplicationView.GetForCurrentView();

            if (gameContext.RequestedWidth != 0 && gameContext.RequestedHeight != 0)
            {
                applicationView.SetPreferredMinSize(new Windows.Foundation.Size(gameContext.RequestedWidth, gameContext.RequestedHeight));
                applicationView.TryResizeView(new Windows.Foundation.Size(gameContext.RequestedWidth, gameContext.RequestedHeight));
            }
        }
예제 #17
0
 private void setMinAppSize(ApplicationView appView)
 {
     appView.SetPreferredMinSize(new Size(480, 800));
     var coreWindow = Windows.UI.Core.CoreWindow.GetForCurrentThread();
 }
예제 #18
0
        private async Task BootstrapFrame(LaunchActivatedEventArgs launchActivatedEventArgs, IActivatedEventArgs activatedEventArgs, string addTaskTitle = null)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                try
                {
                    ApplicationView appView = ApplicationView.GetForCurrentView();
                    this.mainview = appView;
                    SetupTitleBar(appView);
                    SetupStatusBar(appColor);

                    appView.SetPreferredMinSize(new Size(Constants.AppMinWidth, Constants.AppMinHeight));

                    this.bootstraper = new Bootstraper(ApplicationVersion.GetAppVersion());

                    InitializeViewLocator();

                    await this.bootstraper.ConfigureAsync(rootFrame);

                    this.navigationService = Ioc.Resolve <INavigationService>();
                    this.platformService   = Ioc.Resolve <IPlatformService>();

                    this.suspensionManager = new SuspensionManager(Ioc.Resolve <IPersistenceLayer>(), Ioc.Resolve <ISynchronizationManager>(), Ioc.Resolve <ITileManager>());

                    rootFrame.Navigated        += this.OnNavigated;
                    rootFrame.NavigationFailed += this.OnNavigationFailed;

                    // Place the frame in the current Window
                    Window.Current.Content = rootFrame;

                    if (rootFrame.Content == null)
                    {
                        Type   startupPage         = typeof(MainPage);
                        object navigationParameter = launchActivatedEventArgs?.Arguments;

                        var startupManager = Ioc.Resolve <IStartupManager>();
                        if (startupManager.IsFirstLaunch)
                        {
                            startupPage = typeof(WelcomePage);
                        }
                        else if (!String.IsNullOrWhiteSpace(addTaskTitle))
                        {
                            startupPage         = typeof(WelcomePage);
                            navigationParameter = new TaskCreationParameters {
                                Title = addTaskTitle
                            };
                        }

                        SystemNavigationManager.GetForCurrentView().BackRequested += this.OnBackRequested;
                        SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = rootFrame.CanGoBack ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed;
                        Window.Current.VisibilityChanged += this.OnVisibilityChanged;

                        // When the navigation stack isn't restored navigate to the first page,
                        // configuring the new page by passing required information as a navigation parameter
                        rootFrame.Navigate(startupPage, navigationParameter);
                    }

                    if (launchActivatedEventArgs != null)
                    {
                        LauncherHelper.TryHandleArgs(launchActivatedEventArgs.Arguments);
                    }
                    else if (activatedEventArgs != null)
                    {
                        LauncherHelper.TryHandleArgs(activatedEventArgs);
                    }

                    // Ensure the current window is active
                    Window.Current.Activate();
                }
                catch (Exception ex)
                {
                    var messageBoxService = new MessageBoxService(new NavigationService(rootFrame));
                    await messageBoxService.ShowAsync("Error", "2Day was unable to start please send a screenshot of this page to the development team. Details: " + ex);

                    DeviceFamily deviceFamily = DeviceFamily.Unkown;
                    if (this.platformService != null)
                    {
                        deviceFamily = this.platformService.DeviceFamily;
                    }

                    var trackingManager = new TrackingManager(true, deviceFamily);
                    trackingManager.Exception(ex, "Bootstrap", true);
                }
            }
            else
            {
                if (launchActivatedEventArgs != null)
                {
                    LauncherHelper.TryHandleArgs(launchActivatedEventArgs.Arguments);
                }
                else if (activatedEventArgs != null)
                {
                    LauncherHelper.TryHandleArgs(activatedEventArgs);
                }
            }
        }
예제 #19
0
        private void OnAppLaunch(IActivatedEventArgs args, string argument)
        {
            // Uncomment the following lines to display frame-rate and per-frame CPU usage info.
            //#if _DEBUG
            //    if (IsDebuggerPresent())
            //    {
            //        DebugSettings->EnableFrameRateCounter = true;
            //    }
            //#endif

            args.SplashScreen.Dismissed += DismissedEventHandler;

            var           rootFrame = (Window.Current.Content as Frame);
            WeakReference weak      = new WeakReference(this);

            float minWindowWidth  = (float)((double)Resources[ApplicationResourceKeys.Globals.AppMinWindowWidth]);
            float minWindowHeight = (float)((double)Resources[ApplicationResourceKeys.Globals.AppMinWindowHeight]);
            Size  minWindowSize   = SizeHelper.FromDimensions(minWindowWidth, minWindowHeight);

            ApplicationView          appView       = ApplicationView.GetForCurrentView();
            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;

            // For very first launch, set the size of the calc as size of the default standard mode
            if (!localSettings.Values.ContainsKey("VeryFirstLaunch"))
            {
                localSettings.Values["VeryFirstLaunch"] = false;
                appView.SetPreferredMinSize(minWindowSize);
                appView.TryResizeView(minWindowSize);
            }
            else
            {
                ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Auto;
            }

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")) // PC Family
                {
                    // Disable the system view activation policy during the first launch of the app
                    // only for PC family devices and not for phone family devices
                    try
                    {
                        ApplicationViewSwitcher.DisableSystemViewActivationPolicy();
                    }
                    catch (Exception)
                    {
                        // Log that DisableSystemViewActionPolicy didn't work
                    }
                }

                // Create a Frame to act as the navigation context
                rootFrame = App.CreateFrame();

                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(typeof(MainPage), argument))
                {
                    // We couldn't navigate to the main page, kill the app so we have a good
                    // stack to debug
                    throw new SystemException();
                }

                SetMinWindowSizeAndThemeAndActivate(rootFrame, minWindowSize);
                m_mainViewId = ApplicationView.GetForCurrentView().Id;
                AddWindowToMap(WindowFrameService.CreateNewWindowFrameService(rootFrame, false, weak));
            }
            else
            {
                // For first launch, LaunchStart is logged in constructor, this is for subsequent launches.

                // !Phone check is required because even in continuum mode user interaction mode is Mouse not Touch
                if ((UIViewSettings.GetForCurrentView().UserInteractionMode == UserInteractionMode.Mouse) &&
                    (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")))
                {
                    // If the pre-launch hasn't happened then allow for the new window/view creation
                    if (!m_preLaunched)
                    {
                        var newCoreAppView = CoreApplication.CreateNewView();
                        _ = newCoreAppView.Dispatcher.RunAsync(
                            CoreDispatcherPriority.Normal, async() =>
                        {
                            var that = weak.Target as App;
                            if (that != null)
                            {
                                var newRootFrame = App.CreateFrame();

                                SetMinWindowSizeAndThemeAndActivate(newRootFrame, minWindowSize);

                                if (!newRootFrame.Navigate(typeof(MainPage), argument))
                                {
                                    // We couldn't navigate to the main page, kill the app so we have a good
                                    // stack to debug
                                    throw new SystemException();
                                }

                                var frameService = WindowFrameService.CreateNewWindowFrameService(newRootFrame, true, weak);
                                that.AddWindowToMap(frameService);

                                var dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;

                                // CSHARP_MIGRATION_ANNOTATION:
                                // class SafeFrameWindowCreation is being interpreted into a IDisposable class
                                // in order to enhance its RAII capability that was written in C++/CX
                                using (var safeFrameServiceCreation = new SafeFrameWindowCreation(frameService, that))
                                {
                                    int newWindowId = ApplicationView.GetApplicationViewIdForWindow(CoreWindow.GetForCurrentThread());

                                    ActivationViewSwitcher activationViewSwitcher = null;
                                    var activateEventArgs = (args as IViewSwitcherProvider);
                                    if (activateEventArgs != null)
                                    {
                                        activationViewSwitcher = activateEventArgs.ViewSwitcher;
                                    }

                                    if (activationViewSwitcher != null)
                                    {
                                        _ = activationViewSwitcher.ShowAsStandaloneAsync(newWindowId, ViewSizePreference.Default);
                                        safeFrameServiceCreation.SetOperationSuccess(true);
                                    }
                                    else
                                    {
                                        var activatedEventArgs = (args as IApplicationViewActivatedEventArgs);
                                        if ((activatedEventArgs != null) && (activatedEventArgs.CurrentlyShownApplicationViewId != 0))
                                        {
                                            // CSHARP_MIGRATION_ANNOTATION:
                                            // here we don't use ContinueWith() to interpret origin code because we would like to
                                            // pursue the design of class SafeFrameWindowCreate whichi was using RAII to ensure
                                            // some states get handled properly when its instance is being destructed.
                                            //
                                            // To achieve that, SafeFrameWindowCreate has been reinterpreted using IDisposable
                                            // pattern, which forces we use below way to keep async works being controlled within
                                            // a same code block.
                                            var viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
                                                frameService.GetViewId(),
                                                ViewSizePreference.Default,
                                                activatedEventArgs.CurrentlyShownApplicationViewId,
                                                ViewSizePreference.Default);
                                            // SafeFrameServiceCreation is used to automatically remove the frame
                                            // from the list of frames if something goes bad.
                                            safeFrameServiceCreation.SetOperationSuccess(viewShown);
                                        }
                                    }
                                }
                            }
                        });
                    }
                    else
                    {
                        ActivationViewSwitcher activationViewSwitcher = null;
                        var activateEventArgs = (args as IViewSwitcherProvider);
                        if (activateEventArgs != null)
                        {
                            activationViewSwitcher = activateEventArgs.ViewSwitcher;
                        }

                        if (activationViewSwitcher != null)
                        {
                            _ = activationViewSwitcher.ShowAsStandaloneAsync(
                                ApplicationView.GetApplicationViewIdForWindow(CoreWindow.GetForCurrentThread()), ViewSizePreference.Default);
                        }
                        else
                        {
                            TraceLogger.GetInstance().LogError(ViewMode.None, "App.OnAppLaunch", "Null_ActivationViewSwitcher");
                        }
                    }
                    // Set the preLaunched flag to false
                    m_preLaunched = false;
                }
                else // for touch devices
                {
                    if (rootFrame.Content == null)
                    {
                        // When the navigation stack isn't restored navigate to the first page,
                        // configuring the new page by passing required information as a navigation
                        // parameter
                        if (!rootFrame.Navigate(typeof(MainPage), argument))
                        {
                            // We couldn't navigate to the main page,
                            // kill the app so we have a good stack to debug
                            throw new SystemException();
                        }
                    }
                    if (ApplicationView.GetForCurrentView().ViewMode != ApplicationViewMode.CompactOverlay)
                    {
                        if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
                        {
                            // for tablet mode: since system view activation policy is disabled so do ShowAsStandaloneAsync if activationViewSwitcher exists in
                            // activationArgs
                            ActivationViewSwitcher activationViewSwitcher = null;
                            var activateEventArgs = (args as IViewSwitcherProvider);
                            if (activateEventArgs != null)
                            {
                                activationViewSwitcher = activateEventArgs.ViewSwitcher;
                            }
                            if (activationViewSwitcher != null)
                            {
                                var viewId = (args as IApplicationViewActivatedEventArgs).CurrentlyShownApplicationViewId;
                                if (viewId != 0)
                                {
                                    _ = activationViewSwitcher.ShowAsStandaloneAsync(viewId);
                                }
                            }
                        }
                        // Ensure the current window is active
                        Window.Current.Activate();
                    }
                }
            }
        }
예제 #20
0
        public static async Task OpenPropertiesWindowAsync(object item, IShellPage associatedInstance)
        {
            if (item == null)
            {
                return;
            }

            if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
            {
                if (WindowDecorationsHelper.IsWindowDecorationsAllowed)
                {
                    AppWindow appWindow = await AppWindow.TryCreateAsync();

                    Frame frame = new Frame();
                    frame.RequestedTheme = ThemeHelper.RootTheme;
                    frame.Navigate(typeof(Properties), new PropertiesPageNavigationArguments()
                    {
                        Item = item,
                        AppInstanceArgument = associatedInstance
                    }, new SuppressNavigationTransitionInfo());
                    ElementCompositionPreview.SetAppWindowContent(appWindow, frame);
                    (frame.Content as Properties).appWindow = appWindow;

                    appWindow.TitleBar.ExtendsContentIntoTitleBar = true;
                    appWindow.Title            = "PropertiesTitle".GetLocalized();
                    appWindow.PersistedStateId = "Properties";
                    WindowManagementPreview.SetPreferredMinSize(appWindow, new Size(460, 550));

                    bool windowShown = await appWindow.TryShowAsync();

                    if (windowShown)
                    {
                        // Set window size again here as sometimes it's not resized in the page Loaded event
                        appWindow.RequestSize(new Size(460, 550));

                        DisplayRegion displayRegion   = ApplicationView.GetForCurrentView().GetDisplayRegions()[0];
                        Point         pointerPosition = CoreWindow.GetForCurrentThread().PointerPosition;
                        appWindow.RequestMoveRelativeToDisplayRegion(displayRegion,
                                                                     new Point(pointerPosition.X - displayRegion.WorkAreaOffset.X, pointerPosition.Y - displayRegion.WorkAreaOffset.Y));
                    }
                }
                else
                {
                    CoreApplicationView newWindow = CoreApplication.CreateNewView();
                    ApplicationView     newView   = null;

                    await newWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                    {
                        Frame frame          = new Frame();
                        frame.RequestedTheme = ThemeHelper.RootTheme;
                        frame.Navigate(typeof(Properties), new PropertiesPageNavigationArguments()
                        {
                            Item = item,
                            AppInstanceArgument = associatedInstance
                        }, new SuppressNavigationTransitionInfo());
                        Window.Current.Content = frame;
                        Window.Current.Activate();

                        newView = ApplicationView.GetForCurrentView();
                        newWindow.TitleBar.ExtendViewIntoTitleBar = true;
                        newView.Title            = "PropertiesTitle".GetLocalized();
                        newView.PersistedStateId = "Properties";
                        newView.SetPreferredMinSize(new Size(460, 550));

                        bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newView.Id);
                        if (viewShown && newView != null)
                        {
                            // Set window size again here as sometimes it's not resized in the page Loaded event
                            newView.TryResizeView(new Size(460, 550));
                        }
                    });
                }
            }
            else
            {
                var propertiesDialog = new PropertiesDialog();
                propertiesDialog.propertiesFrame.Tag = propertiesDialog;
                propertiesDialog.propertiesFrame.Navigate(typeof(Properties), new PropertiesPageNavigationArguments()
                {
                    Item = item,
                    AppInstanceArgument = associatedInstance
                }, new SuppressNavigationTransitionInfo());
                await propertiesDialog.ShowAsync(ContentDialogPlacement.Popup);
            }
        }