微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

默认情况下如何以全屏模式启动 uwp webview 应用程序

如何解决默认情况下如何以全屏模式启动 uwp webview 应用程序

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

>

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

ApplicationView view = ApplicationView.GetForCurrentView();
view.TryEnterFullScreenMode();

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

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

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

main.js 文件代码如下

(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();

})();

有关如何解决此问题的任何建议。

解决方法

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。