【问题标题】:WIndows 8 Metro List View Event ListenerWIndows 8 Metro 列表视图事件监听器
【发布时间】:2012-07-27 19:47:10
【问题描述】:

我正在尝试为 Windows 8 创建一个简单的 HTML Metro 应用程序。我想显示一个列表视图,并根据单击的项目在屏幕上显示不同的内容。这听起来微不足道,对吧? 但它不起作用!这是我的代码:

<div  id="frameListViewTemplate"  data-win-control="WinJS.Binding.Template">
   <img data-win-bind="src: picture" class="thumbnail" />
</div>
<div id="basicListView" data-win-control="WinJS.UI.ListView" 
    data-win-options="{itemDataSource : DataExample.itemList.dataSource, itemTemplate: select('#frameListViewTemplate'),onselectionchanged : handler}">
</div>

比在 defult.js 中

var myListView = document.getElementById("basicListView").winControl;
myListView.addEventListener("selectionchanged", handler);

和处理程序:

function handler() {
console.log("Inside the handler  : ");
}
handler.supportedForProcessing = true;

所以处理程序永远不会被调用。我的问题是:如何将事件侦听器及其处理程序添加到 listview 控件。 如何识别列表视图中的哪个元素被单击。

附: 列表视图在我的应用程序中正确显示。 谢谢你的帮助, J

【问题讨论】:

    标签: windows-8 microsoft-metro


    【解决方案1】:

    要获取被“点击”的项目,您需要使用 itemInvoked。当用户在项目上交叉滑动以选择它而不是点击/单击以“调用”它时,将发生选择更改。

    http://msdn.microsoft.com/en-us/library/windows/apps/br211827.aspx 有一些基本的细节。

    【讨论】:

      猜你喜欢
      • 2022-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-03
      • 2016-02-28
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2014-09-15
      相关资源
      最近更新 更多