繁体   English   中英

导航2-3次后应用程序延迟

[英]Application Lags after 2-3 times Navigates

您好 ,我正在尝试创建我的第一个应用程序,并将其发布给我的网站。 我快结束了,但是应用程序无法顺利运行。 作为我的老问题,如何创建GoBack按钮,我得到了Example的答案。 在示例中,使用GoBack按钮,我继续将其他页面添加到“应用程序”中。 前2-3次,如果我从页面返回,则运行顺利,第4次和下一次,它会滞后。 有人可以检查代码中的错误或其他内容吗? 该页面基于Webview。

我在Visual Studio中遇到此错误:

不建议使用Windows.UI.ApplicationSettings.SettingsPane.getForCurrentView方法。不建议使用SettingsPane,并且可能无法在所有平台上使用。有关更多信息,请参见MSDN。评估代码(2)(1,7)

CSP14312:主机定义的策略:内联脚本中的资源违反指令'script-src ms-appx:'unsafe-eval'。资源将被阻止。


Default.js

(function () {
"use strict";

var activation = Windows.ApplicationModel.Activation;
var app = WinJS.Application;
var nav = WinJS.Navigation;
var sched = WinJS.Utilities.Scheduler;
var ui = WinJS.UI;

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

app.onactivated = function (args) {
    if (args.detail.kind === activation.ActivationKind.launch) {
        if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
            var currentview = Windows.UI.Core.SystemNavigationManager.getForCurrentView();
            currentview.appViewBackButtonVisibility = Windows.UI.Core.AppViewBackButtonVisibility.visible;
            currentview.onbackrequested = onBackRequested;
            function onBackRequested(eventArgs) {
                if (WinJS.Navigation.canGoBack) {
                    WinJS.Navigation.back(1).done(function (successInformation) {
                        /*this is the success function*/
                    }, function (error) {
                        /*this is the error function*/
                    });
                }
            }
        } else {
            // TODO: This application was suspended and then terminated.
            // To create a smooth user experience, restore application state here so that it looks like the app never stopped running.
        }

        nav.history = app.sessionState.history || {};
        nav.history.current.initialPlaceholder = true;

        // Optimize the load of the application and while the splash screen is shown, execute high priority scheduled work.
        ui.disableAnimations();
        var p = ui.processAll().then(function () {
            return nav.navigate(nav.location || Application.navigator.home, nav.state);
        }).then(function () {
            return sched.requestDrain(sched.Priority.aboveNormal + 1);
        }).then(function () {
            ui.enableAnimations();
        });

        args.setPromise(WinJS.UI.processAll());
        ApplicationView.preferredLaunchWindowingMode = ApplicationViewWindowingMode.fullScreen;
    }
};

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.sessionState.history = nav.history;
};

app.start();
})();

Navigator.js

(function () {
"use strict";

var nav = WinJS.Navigation;

WinJS.Namespace.define("Application", {
    PageControlNavigator: WinJS.Class.define(
        // Define the constructor function for the PageControlNavigator.
        function PageControlNavigator(element, options) {
            this._element = element || document.createElement("div");
            this._element.appendChild(this._createPageElement());

            this.home = options.home;

            this._eventHandlerRemover = [];

            var that = this;
            function addRemovableEventListener(e, eventName, handler, capture) {
                e.addEventListener(eventName, handler, capture);
                that._eventHandlerRemover.push(function () {
                    e.removeEventListener(eventName, handler);
                });
            };

            addRemovableEventListener(nav, 'navigating', this._navigating.bind(this), false);
            addRemovableEventListener(nav, 'navigated', this._navigated.bind(this), false);

            window.onresize = this._resized.bind(this);

            Application.navigator = this;
        }, {
            home: "",
            /// <field domElement="true" />
            _element: null,
            _lastNavigationPromise: WinJS.Promise.as(),
            _lastViewstate: 0,

            // This is the currently loaded Page object.
            pageControl: {
                get: function () { return this.pageElement && this.pageElement.winControl; }
            },

            // This is the root element of the current page.
            pageElement: {
                get: function () { return this._element.firstElementChild; }
            },

            // This function disposes the page navigator and its contents.
            dispose: function () {
                if (this._disposed) {
                    return;
                }

                this._disposed = true;
                WinJS.Utilities.disposeSubTree(this._element);
                for (var i = 0; i < this._eventHandlerRemover.length; i++) {
                    this._eventHandlerRemover[i]();
                }
                this._eventHandlerRemover = null;
            },

            // Creates a container for a new page to be loaded into.
            _createPageElement: function () {
                var element = document.createElement("div");
                element.setAttribute("dir", window.getComputedStyle(this._element, null).direction);
                element.style.position = "absolute";
                element.style.visibility = "hidden";
                element.style.width = "100%";
                element.style.height = "100%";
                return element;
            },

            // Retrieves a list of animation elements for the current page.
            // If the page does not define a list, animate the entire page.
            _getAnimationElements: function () {
                if (this.pageControl && this.pageControl.getAnimationElements) {
                    return this.pageControl.getAnimationElements();
                }
                return this.pageElement;
            },

            _navigated: function () {
                this.pageElement.style.visibility = "";
                WinJS.UI.Animation.enterPage(this._getAnimationElements()).done();
            },

            // Responds to navigation by adding new pages to the DOM. 
            _navigating: function (args) {
                var newElement = this._createPageElement();
                this._element.appendChild(newElement);

                this._lastNavigationPromise.cancel();

                var that = this;

                function cleanup() {
                    if (that._element.childElementCount > 1) {
                        var oldElement = that._element.firstElementChild;
                        // Cleanup and remove previous element 
                        if (oldElement.winControl) {
                            if (oldElement.winControl.unload) {
                                oldElement.winControl.unload();
                            }
                            oldElement.winControl.dispose();
                        }
                        oldElement.parentNode.removeChild(oldElement);
                        oldElement.innerText = "";
                    }
                }

                this._lastNavigationPromise = WinJS.Promise.as().then(function () {
                    return WinJS.UI.Pages.render(args.detail.location, newElement, args.detail.state);
                }).then(cleanup, cleanup);

                args.detail.setPromise(this._lastNavigationPromise);
            },

            // Responds to resize events and call the updateLayout function
            // on the currently loaded page.
            _resized: function (args) {
                if (this.pageControl && this.pageControl.updateLayout) {
                    this.pageControl.updateLayout.call(this.pageControl, this.pageElement);
                }
            },
        }
    )
});
})();

Windows 10中的所有平台均无法使用SettingsPane

https://msdn.microsoft.com/zh-cn/library/windows/apps/windows.ui.applicationsettings.settingspane

要解决此问题,请转到“设置”,“添加/删除程序”,然后选择“ Visual Studio”。 通过选择修改选项,您将能够添加尚未安装的组件。 我发现未安装的是Windows Phone 8.0 SDK组件,安装后可解决此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM