Display variable height elements in ListLayout

I have a Metro application for WinJs containing ListViewvariable height elements. This is mainly done in the same way as in scenario 4 of the "HTML ListView HTML Element Templates". The function is groupInfoused to enable the cell of the cell GridLayoutassociated with the ListView:

items in grid layout

Now in my snap view application, I would like the elements to scroll vertically, so I tried replacing GridLayoutwith ListLayout. This leads to vertical scrolling, but now there is no cell span and the elements overlap:

items in list layout

I used the function groupInfoin the same way as with GridLayout, but it seems to ignore it:

layout: { 
    groupInfo: groupInfo, 
    type: WinJS.UI.ListLayout 
} 

Is there any way to use variable size elements in ListLayout? Some of my items have more content than others, and I would really like to use tiles of different sizes to show everything optimally.

+5
source share
2 answers

old post

Yes, of course you can customize everything. I think that your rendering problem occurs because of this, you can forget forceLayout.

ready: function (element, options) { 
            element.querySelector("#listView").winControl.forceLayout(); 
        }

I do not have my Windows 8 next to me, so if no one else answers and the problem arose not from forceLayout. I will update the answer for the night.

I hope this help.

Good, so I misunderstood your problem before.

Here is something that should satisfy you.

, JavaScript CSS.

, JavaScript, , Grid Application, . 4.js .

function MyCellSpanningJSTemplate(itemPromise) {
    return itemPromise.then(function (currentItem) {
        var result = document.createElement("div");

        // Use source data to decide what size to make the
        // ListView item
        result.className = currentItem.data.type;
        result.style.overflow = "hidden";

        // Display image
        var image = document.createElement("img");
        image.className = "regularListIconTextItem-Image";
        image.src = currentItem.data.picture;
        result.appendChild(image);

        var body = document.createElement("div");
        body.className = "regularListIconTextItem-Detail";
        body.style.overflow = "hidden";
        result.appendChild(body);

        // Display title
        var title = document.createElement("h4");
        title.innerText = currentItem.data.title;
        body.appendChild(title);

        // Display text
        var fulltext = document.createElement("h6");
        fulltext.innerText = currentItem.data.text;
        body.appendChild(fulltext);

        return result;
    });
}

var appViewState = Windows.UI.ViewManagement.ApplicationViewState;
var appView = Windows.UI.ViewManagement.ApplicationView;
var ui = WinJS.UI;

(function () {
    "use strict";
    var page = WinJS.UI.Pages.define("/html/scenario4.html", {
        initializeLayout: function (listView, viewState) {
            /// <param name="listView" value="WinJS.UI.ListView.prototype" />

            if (viewState === appViewState.snapped) {
                listView.layout = new ui.ListLayout();
            } 
            else {
                listView.layout = new ui.GridLayout({ groupInfo: groupInfo });
            }
        },
        ready: function (element, options) {
            var listView = element.querySelector("#listView").winControl;
            this.initializeLayout(listView, appView.value);
        },
        updateLayout: function (element, viewState, lastViewState) {

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

            if (lastViewState !== viewState) {
                if (lastViewState === appViewState.snapped || viewState === appViewState.snapped) {                   
                    this.initializeLayout(listView, viewState);
                } 
                else {
                    listView.layout = new ui.GridLayout({ groupInfo: groupInfo });
                }
            }
        }
    });
})();

layout script4.html, 4.js

, , . (Btw , , ).

script4.css , CSS 3 -, . snapped . 4.css

@media screen and (-ms-view-state: snapped) {
    #listView {
        max-width: 260px;
        height: 280px;
        border: solid 2px rgba(0, 0, 0, 0.13);
    }

    .regularListIconTextItem {
        max-width: 250px;
        max-height: 70px;
        padding: 5px;
        overflow: hidden;
        display: -ms-grid;
    }

    .smallListIconTextItem {
        max-width: 250px;
        max-height: 70px;
        padding: 5px;
        overflow: hidden;
        background-color: Pink;
        display: -ms-grid;
    }

    /* Medium size */
    .mediumListIconTextItem {
        max-width: 250px;
        max-height: 70px;
        padding: 5px;
        overflow: hidden;
        background-color: LightGreen;
        display: -ms-grid;
    }

    /* Large size */
    .largeListIconTextItem {
        max-width: 250px;
        max-height: 70px;
        padding: 5px;
        overflow: hidden;
        background-color: LightBlue;
        display: -ms-grid;
    }
}

, ;)

0

, , MyCellSpanningJSTemplate, . .

1) :

    <div id="listLayoutItemTemplate" data-win-control="WinJS.Binding.Template" style="display: none">
        <div class="regularListIconItem">
            <img src="#" class="regularListIconItem-Image" data-win-bind="src: picture" />
        </div>
    </div>

2) (. http://code.msdn.microsoft.com/windowsapps/Snap-Sample-2dc21ee3)

3) , 1.

var listView = document.querySelector("#listView").winControl;
listView.itemTemplate = listLayoutItemTemplate;
0

All Articles