4

我想更改 ListView 项目的默认选择模板。默认情况下,3 像素宽的灰色边框应用于当前选定的项目:

在此处输入图像描述

我确实在 ui.js 中发现 _selectionTemplate 属性在内部设置为默认边框:

var selectionBorder = createNodeWithClass(WinJS.UI._selectionBorderContainerClass);
selectionBorder.appendChild(createNodeWithClass(WinJS.UI._selectionBorderClass + " " + WinJS.UI._selectionBorderTopClass));
selectionBorder.appendChild(createNodeWithClass(WinJS.UI._selectionBorderClass + " " + WinJS.UI._selectionBorderRightClass));
selectionBorder.appendChild(createNodeWithClass(WinJS.UI._selectionBorderClass + " " + WinJS.UI._selectionBorderBottomClass));
selectionBorder.appendChild(createNodeWithClass(WinJS.UI._selectionBorderClass + " " + WinJS.UI._selectionBorderLeftClass));

this._selectionTemplate = [];
this._selectionTemplate.push(createNodeWithClass(WinJS.UI._selectionBackgroundClass));
this._selectionTemplate.push(selectionBorder);
this._selectionTemplate.push(createNodeWithClass(WinJS.UI._selectionCheckmarkBackgroundClass));
var checkmark = createNodeWithClass(WinJS.UI._selectionCheckmarkClass);
checkmark.innerText = WinJS.UI._SELECTION_CHECKMARK;
this._selectionTemplate.push(checkmark);

但是,由于 _selectionTemplate 是私有的,因此修改 _selectionTemplate 属性本身似乎违背了 ListView 的设计。修改此默认选择模板是否有更好的解决方法?

4

1 回答 1

8

覆盖默认模板使用的 CSS 类。例如,这会将边框更改为红色:

.win-listview .win-container:hover{
    outline: rgba(255, 0, 0, 0.3) solid 3px;
}
于 2012-08-24T18:39:14.700 回答