我正在尝试在应用程序被捕捉时将listView控件的布局从“GridView”更改为“ListView”。当然,它应该在任何其他状态下返回“GridView”。我写了一些代码,但它不起作用,所以我想知道为什么......
这是我写的代码:
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();
}
答案 0 :(得分:2)
从here获取,只需侦听resize事件并对listview的布局属性进行更改。
我无法告诉您的代码是否正在调用相似的代码,因此以下是您需要的整个方法
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(); } lastViewState = currentViewState; });
答案 1 :(得分:0)
尝试调用list.forceLayout()它多次保存了我的生命......; - )