1

我想将关于按钮(可能是链接)添加到设置魅力。但我不想在设置魅力中显示内容,我需要在应用程序中导航 About.html 页面。应用程序设置示例对我没有帮助。有没有办法做到这一点?我需要用 JavaScript 和 HTML 来做这件事;)

目前我将下面的代码添加到 default.js

 app.onactivated = function (eventObject) {
        if (eventObject.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
            //WinJS.UI.disableAnimations();

            WinJS.Application.onsettings = function (e) {
                e.detail.applicationcommands = {
                    "about": {
                        title: "About", href:"/html/About.html"
                        }
                }
                WinJS.UI.SettingsFlyout.populateSettings(e);
                };
...
}

我在 html 文件夹下创建了一个 HTML 文件。这是 About.html 的代码

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>About</title>

    <!-- WinJS references -->
    <script src="//Microsoft.WinJS.1.0/js/base.js"></script>
    <script src="//Microsoft.WinJS.1.0/js/ui.js"></script>


    <link rel="stylesheet" type="text/css" href="css/staticPages.css" />
    <script type="text/javascript" src="/js/navigator.js"></script>
    <script src="/js/jq-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="/js/networkInfo.js"></script>
    <script src="/js/About.js" type="text/javascript"></script>
</head>
    <body>
    <div id="siluet" class="siluet">&nbsp;</div>
    <div id="contentDetay">
        <button id="backbutton" class="win-backbutton">
        </button>
        <img id="headLogo" src="/images/head_logo.png" alt="XYZ" />
        <progress id="progressRing"></progress>
        <div id="title"><h1 id="groupNameHeader">Group Name</h1><h1 id="pageTitle">Page Title</h1><div id="sectionSelectArrow">&nbsp;</div></div>
        <div id="menuPopUp">
            <select id="menuList" multiple="multiple"></select>
        </div>

        <div id="staticContainer"></div>
        <div id="noSnapView">
            <p>İçeriği görüntüleyebilmek için ekranı büyütün</p>
        </div>
    </div>
</body>

</html>

当我单击 Settings Charm Bar 下的 About 链接时出现问题,我在 /js 文件夹下的 About.js 文件中出现错误。

(function () {
    'use strict';

    var dataItems;
    var groupIndex;
    var sectionIndex;
    var itemIndex;

    function ready(element, options) {

        networkInfo.getInfo();
        pageTitle.style.display = "none"; // pageTitle.style is undefined

        var that = this;
        groupNameHeader.innerText = "About"; // groupNameHeader is undefined

        var aboutContent; // This content is retrieving from web service
        // staticContainer is undefined
        staticContainer.innerHTML = window.toStaticHTML(aboutContent);

    }  

     WinJS.Namespace.define("appGlobal", {
        fadeProgressRingOut: fadeProgressRingOut
    });
    WinJS.UI.Pages.define("/html/About.html", {
        ready: ready
    });

})();

如您所见,每个 HTML 元素在 .js 文件中都是未定义的;但我找不到原因。

4

2 回答 2

3

JavaScript App Settings 示例详细展示了如何将按钮添加到 Settings Charm 。

这是一个让您入门的片段:

WinJS.Application.onsettings = function (e) {
    e.detail.applicationcommands = {
        "aboutDiv": { title: "About", href: "/html/About.html" }
    };
    WinJS.UI.SettingsFlyout.populateSettings(e);
};
于 2012-09-21T13:49:00.553 回答
2

像这样更改代码可能会解决您的问题:

app.onactivated = function (eventObject) {
    if (eventObject.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
        //WinJS.UI.disableAnimations();

       var settingsPane = Windows.UI.ApplicationSettings.SettingsPane.getForCurrentView();
       settingsPane.addEventListener("commandsrequested", onCommandsRequested);

    // ...

}

function onSettingsCommand(){
    nav.navigate("html/about.html");
}

function onCommandsRequested(eventArgs){
    var settingsCommand = new Windows.UI.ApplicationSettings.SettingsCommand("about", About", onSettingsCommand);
    eventArgs.request.applicationCommands.append(settingsCommand);
}
于 2012-09-24T13:12:40.840 回答