你好下, 我正在尝试创建我的第一个应用程序,并将其发布到我的网站。我在最后,但应用程序将无法顺利运行。作为我的旧问题,如何创建一个GoBack按钮,我得到了一个示例答案。在示例中,使用GoBack按钮,我继续将其他页面添加到应用程序中。前2-3次,如果我从一个页面返回它顺利进行,对于4次和下次,它会滞后。有人可以检查错误代码或其他东西。 Page是基于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);
}
},
}
)
});
})();
答案 0 :(得分:0)
SettingsPane 类在Windows 10中不适用于所有平台
(https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.applicationsettings.settingspane)
要解决此问题,请转到“设置”,“添加/删除程序”,然后选择“Visual Studio”。通过选择修改选项,您将能够添加尚未安装的组件。我发现它是未安装的Windows Phone 8.0 SDK组件,一旦安装就修复了问题。