Detail List View in Windows Store App


In this article I describe how to create a Windows Store App for Detail List View using JavaScript. This app shows how to use the List View to create a detail list, similar to what you'd see in most news screens. The List View provides a list of news. Selecting an item in that list updates the bottom pane.

I assume you can create a simple Windows Store App using JavaScript. For more help visit Simple Windows Store Apps using JavaScript.

To start the creation of the app, add two JavaScript pages by right-clicking on the js folder in the Solution Explorer and select "Add" > "New item" > "JavaScript Page" and then provide an appropriate name. In the same way, add one HTML page to your project.


Write the following code in default.html:

<!DOCTYPE html>



    <meta charset="utf-8" />


    <link rel="stylesheet" href="//Microsoft.WinJS.1.0/css/ui-light.css" />

    <script src="//Microsoft.WinJS.1.0/js/base.js"></script>

    <script src="//Microsoft.WinJS.1.0/js/ui.js"></script>

    <link rel="stylesheet" href="/css/default.css" />

    <script src="/js/default.js"></script>


<body role="application" style="background-color: lightblue">

    <center><div id="rootGrid">

        <div id="content">

            <h1 id="featureLabel"></h1>

            <div id="contentHost"></div>





Write the following code in default.js:

(function () {

    "use strict";

    var appTitle = "";

    var pages = [       

        { url: "page.html"}


    function activated(eventObject) {

        if (eventObject.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {

            eventObject.setPromise(WinJS.UI.processAll().then(function () {

                var url = WinJS.Application.sessionState.lastUrl || pages[0].url;

                return WinJS.Navigation.navigate(url);




    WinJS.Navigation.addEventListener("navigated", function (eventObject) {

        var url = eventObject.detail.location;

        var host = document.getElementById("contentHost");

        host.winControl && host.winControl.unload && host.winControl.unload();


        eventObject.detail.setPromise(WinJS.UI.Pages.render(url, host, eventObject.detail.state).then(function () {

            WinJS.Application.sessionState.lastUrl = url;



    WinJS.Namespace.define("App", {

        appTitle: appTitle,

        pages: pages


    WinJS.Application.addEventListener("activated", activated, false);



Write the following code in page.html:

<!DOCTYPE html>




    <script src="/js/script.js"></script>



    <div data-win-control="App.pageInput">


    <div data-win-control="App.pageOutput">

        <div id="mediumListIconTextTemplate" data-win-control="WinJS.Binding.Template" style="display: none">

            <div class="mediumListIconTextItem">

                <img src="#" class="mediumListIconTextItem-Image" data-win-bind="src: picture" />

                <div class="mediumListIconTextItem-Detail">

                    <h4 data-win-bind="innerText: title"></h4>

                    <h6 data-win-bind="innerText: text"></h6>




        <div id="inbox">

            <div id="listView2"




                    itemDataSource: myNewsData.dataSource,

                    itemTemplate: mediumListIconTextTemplate,

                    selectionMode: 'multi',

                    tapBehavior: 'directSelect',

                    layout: { type: WinJS.UI.ListLayout }



            <div id="inboxNews">

                <h2 id="inboxNews_Text"></h2>

                <h6 id="inboxNews_Title"></h6>

                <div id="inboxNews_Body"></div>






Write the following code in script.js:

var myNewsData = new WinJS.Binding.List([

        { title: "Sports News", text:"Deepak Arora", picture: "images/1.jpg" },

        { title: "Wheather News", text:"Deepak Arora", picture: "images/1.jpg" },

        { title: "Politics New ", text:"Deepak Arora", picture: "images/1.jpg" },

        { title: "World news", text:"Deepak Arora", picture: "images/1.jpg" }


(function () {

    "use strict";

    var page = WinJS.UI.Pages.define("page.html", {

        ready: function (element, options) {

            var NewsTitle = element.querySelector("#inboxNews_Title");

            var NewsText = element.querySelector("#inboxNews_Text");

            var NewsBody = element.querySelector("#inboxNews_Body");

            var listView = element.querySelector("#listView2").winControl;


            function selectionChangedHandler() {

                var selectionCount = listView.selection.count();

                if (selectionCount === 1) {

                    listView.selection.getItems().done(function (items) {

                        inboxNews_Title.innerText = "From: " + items[0].data.text;

                        inboxNews_Text.innerText = items[0].data.title;

               = "black";

                        inboxNews_Body.innerText = "\n\nNews Body";


                } else {

                    inboxNews_Title.innerText = "";

                    inboxNews_Text.innerText = "";

           = "green";

                    if (selectionCount > 1) {

                        inboxNews_Body.innerText = "Multiple Newss are selected!";

                    } else {

                        inboxNews_Body.innerText = "No News selected!";




            listView.addEventListener("selectionchanged", selectionChangedHandler, false);

            listView.itemDataSource.getCount().done(function (itemCount) {

                var initialSelection = (itemCount > 0) ? 0 : [];









In this app I described how to get the details of an item in a List View in a Windows Store App using JavaScript. I hope this article has helped you to understand this topic. Please share if you know more about this. Your feedback and constructive contributions are welcome.

Similar Articles