首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何默认全屏启动uwp webview app

如何默认全屏启动uwp webview app
EN

Stack Overflow用户
提问于 2021-02-24 13:27:45
回答 1查看 244关注 0票数 0

在Visual Studio 2017的帮助下,我们已经创建了一个完全成熟的UWP webview应用程序(WinJs)。最近通过微软文档和stackoverflow线程,我们发现uwp应用程序可以在去掉标题栏的情况下全屏启动。

以下代码需要插入到App.Xaml.Cs文件中

代码语言:javascript
运行
复制
ApplicationView view = ApplicationView.GetForCurrentView();
view.TryEnterFullScreenMode();

但这里的问题是,我们无法找到此文件来插入此文件。可能是因为我选择了WinJS模板,我不知道。

其他重要文件包括main.js | packageapp.manifest文件。我不知道这段代码是否可以与这两个文件中的任何一个集成。

编辑:在roy的帮助下,根据windows通用示例github中给出的示例修改了主js文件,但仍然无法打开全屏。

main.js文件代码如下所示

代码语言:javascript
运行
复制
(function () {
    "use strict";

    var app = WinJS.Application;
    var activation = Windows.ApplicationModel.Activation;
    var isFirstActivation = true;

    var ViewManagement = Windows.UI.ViewManagement;
    var ApplicationViewWindowingMode = ViewManagement.ApplicationViewWindowingMode;
    var ApplicationView = ViewManagement.ApplicationView;

    
        
    function onLaunchInFullScreenModeChanged() {
        ApplicationView.preferredLaunchWindowingMode = launchInFullScreenMode.checked ? ApplicationViewWindowingMode.fullScreen : ApplicationViewWindowingMode.auto;
    }

    app.onactivated = function (args) {
        if (args.detail.kind === activation.ActivationKind.voiceCommand) {
            // TODO: Handle relevant ActivationKinds. For example, if your app can be started by voice commands,
            // this is a good place to decide whether to populate an input field or choose a different initial view.
        }
        else if (args.detail.kind === activation.ActivationKind.launch) {
            launchInFullScreenMode.addEventListener("click", onLaunchInFullScreenModeChanged);

            launchInFullScreenMode.checked = ApplicationView.preferredLaunchWindowingMode == ApplicationViewWindowingMode.fullScreen;
            // A Launch activation happens when the user launches your app via the tile
            // or invokes a toast notification by clicking or tapping on the body.
            if (args.detail.arguments) {
                // TODO: If the app supports toasts, use this value from the toast payload to determine where in the app
                // to take the user in response to them invoking a toast notification.
            }
            else if (args.detail.previousExecutionState === activation.ApplicationExecutionState.terminated) {
                // TODO: This application had been suspended and was then terminated to reclaim memory.
                // To create a smooth user experience, restore application state here so that it looks like the app never stopped running.
                // Note: You may want to record the time when the app was last suspended and only restore state if they've returned after a short period.
            }
        }

        if (!args.detail.prelaunchActivated) {
            // TODO: If prelaunchActivated were true, it would mean the app was prelaunched in the background as an optimization.
            // In that case it would be suspended shortly thereafter.
            // Any long-running operations (like expensive network or disk I/O) or changes to user state which occur at launch
            // should be done here (to avoid doing them in the prelaunch case).
            // Alternatively, this work can be done in a resume or visibilitychanged handler.
        }

        if (isFirstActivation) {
            // TODO: The app was activated and had not been running. Do general startup initialization here.
            document.addEventListener("visibilitychange", onVisibilityChanged);
            args.setPromise(WinJS.UI.processAll();
            launchInFullScreenMode.addEventListener("click", onLaunchInFullScreenModeChanged);
            launchInFullScreenMode.checked = ApplicationView.preferredLaunchWindowingMode == ApplicationViewWindowingMode.fullScreen;
        }

        isFirstActivation = false;
    };

    function onVisibilityChanged(args) {
        if (!document.hidden) {
            // TODO: The app just became visible. This may be a good time to refresh the view.
        }
    }

    app.oncheckpoint = function (args) {
        // TODO: This application is about to be suspended. Save any state that needs to persist across suspensions here.
        // You might use the WinJS.Application.sessionState object, which is automatically saved and restored across suspension.
        // If you need to complete an asynchronous operation before your application is suspended, call args.setPromise().
    };

    app.start();

})();

关于如何解决这个问题的任何建议。

EN

回答 1

Stack Overflow用户

发布于 2021-02-24 16:14:39

您可以将代码放在JS文件中,您所显示的HTML将引用该文件。

这里曾经有一个JS UWP FullScreenMode示例:FullScreenMode JS。尽管它已归档,但您仍然可以查看scenario2-launch.jsscenario1-basic.js.它展示了如何在JavaScript中使用这些API。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66345163

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档