0

I am trying to change the layout of my listView control from "GridView" to "ListView" when application gets snapped. Of course, it should return to "GridView" in any other state. I wrote some code, but it doesn't work, so I wonder why...

This is the code I've written:

var viewState = Windows.UI.ViewManagement.ApplicationView;
var list = document.getElementById("messageDisplay").winControl;
if (viewState == Windows.UI.ViewManagement.ApplicationViewState.snapped) {
    list.layout = new WinJS.UI.ListLayout();
}
else
{
    list.layout = new WinJS.UI.GridLayout();
}
4

2 回答 2

2

这里获取只需监听 resize 事件并对列表视图的布局属性进行更改。

我不知道你的代码在哪里调用了类似的代码,所以这是你需要的整个方法

window.addEventListener("resize", function (e) {
    var currentViewState = Windows.UI.ViewManagement.ApplicationView.value;
    var snapped = Windows.UI.ViewManagement.ApplicationViewState.snapped;

    if (currentViewState === snapped) {
        that.listView.layout = new WinJS.UI.ListLayout();
    }
    else if (lastViewState === snapped && currentViewState !== snapped) {
        that.listView.layout = new WinJS.UI.GridLayout();
    }

    上一个视图状态 = 当前视图状态;
});

于 2013-04-26T18:35:23.663 回答
0

尝试调用 list.forceLayout() 它多次救了我的命... ;-)

于 2013-04-27T08:43:40.987 回答