sth*_*sth 5 listview microsoft-metro winjs
我有一个WinJs metro应用程序包含一个ListView可变高度的项目.它基本上与"HTML ListView项模板"示例中的场景4中的方式相同.甲groupInfo功能用于使细胞企业跨越式GridLayout使用ListView相关联:

现在在我的应用程序的快照视图中我想要垂直滚动的项目,所以我尝试GridLayout用a 替换ListLayout.这会导致垂直滚动,但现在缺少单元格并且项目重叠:

我使用的groupInfo功能与使用相同GridLayout,但似乎被忽略了:
layout: {
groupInfo: groupInfo,
type: WinJS.UI.ListLayout
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在一个ListLayout?中使用可变大小的项目?我的一些项目比其他项目有更多的内容,我真的想使用不同大小的瓷砖以最佳方式显示所有内容.
旧帖子
是的,您当然可以定制一切。我认为你的渲染问题来自于此,你可能已经忘记了,
forceLayout.Run Code Online (Sandbox Code Playgroud)ready: function (element, options) { element.querySelector("#listView").winControl.forceLayout(); }我附近没有 Windows 8,因此如果没有其他人回复并且问题不是来自我,
forceLayout我会在晚上之前更新回复。我希望这有帮助。
好吧,我之前误解了你的问题。
这是应该让您满意的东西。
问题是您必须在 JavaScript 和 CSS 文件中管理应用程序的不同视图状态。
因此,关于 JavaScript,我使用了两个可以在网格应用程序模板中找到的函数。所以我修改了scenario4.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 });
}
}
}
});
})();
Run Code Online (Sandbox Code Playgroud)
layout然后我删除了scene4.html 中 listview 的整个属性,因为我在 scene4.js 中创建了上面的布局
因此,您的列表视图根据视图状态使用不同的布局,但您将获得与之前相同的结果(顺便说一句,您必须在处于捕捉模式时更改场景才能查看结果)。
因此,我们只需要根据视图状态更新 scene4.css,在 CSS 3 中,我们有媒体查询,可以让我们做到这一点。然后根据此处的视图状态,snapped我们将覆盖我们的属性。您只需将下面的代码添加到您的 scene4.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;
}
}
Run Code Online (Sandbox Code Playgroud)
希望这次有帮助;)