Windows store apps 在WinJS中右键单击时停止显示AppBar控件
我试图仅在用户从列表视图中选择项目时显示。我使用appBar.show()和appBar.hide()方法显示了应用程序栏,但这不是唯一可以显示的时间Windows store apps 在WinJS中右键单击时停止显示AppBar控件,windows-store-apps,winjs,appbar,Windows Store Apps,Winjs,Appbar,我试图仅在用户从列表视图中选择项目时显示。我使用appBar.show()和appBar.hide()方法显示了应用程序栏,但这不是唯一可以显示的时间 当我右键单击页面但没有选择任何内容时,应用程序栏仍会显示。我如何才能停止它的显示?我在我的免费电子书的应用程序栏部分(第480页)回答这个问题: 提示:要防止应用程序/导航栏出现,您可以执行以下两种操作之一 东西。首先,防止应用程序栏或导航栏出现 (对于任何手势),将控件的disabled属性设置为true。 第二,如果你想阻止它,比如说,右键点
当我右键单击页面但没有选择任何内容时,应用程序栏仍会显示。我如何才能停止它的显示?我在我的免费电子书的应用程序栏部分(第480页)回答这个问题: 提示:要防止应用程序/导航栏出现,您可以执行以下两种操作之一 东西。首先,防止应用程序栏或导航栏出现 (对于任何手势),将控件的disabled属性设置为true。 第二,如果你想阻止它,比如说,右键点击 特定元素(如画布),请收听contextmenu (右键单击)该元素的事件并调用 处理程序中的eventArgs.preventDefault()
经过大量的研究,我发现对我来说最好的选择是让应用程序栏自然显示,而不是显示/隐藏命令
<div id="appBar"
data-win-control="WinJS.UI.AppBar"
data-win-options="{placement:'bottom', layout:'commands'}">
<button data-win-control="WinJS.UI.AppBarCommand"
data-win-options="{id:'switchTradeDirection',
type:'button',
label:'Switch Direction',
section:'selection'}"></button>
<button data-win-control="WinJS.UI.AppBarCommand"
data-win-options="{id:'secondary1',
type:'button',
label:'Secondary1',
section:'selection'}"></button>
<div data-win-control="WinJS.UI.AppBarCommand"
data-win-options="{ id: 'list',
extraClass:'multiSelect',
type: 'content',
label:'List',
section: 'selection'}">
<select class="options">
<option>Option1</option>
<option>Option2</option>
<option>Option3</option>
<option>Option4</option>
</select>
</div>
</div>
var appBarDiv = document.getElementById('appBar');
var appBar = appBarDiv.winControl;
if (selectedCount == 2) {
appBar.showCommands(appBarDiv.querySelectorAll('.multiSelect'));
appBar.sticky = true;
appBar.show();
} else {
appBar.hide();
appBar.hideCommands(appBarDiv.querySelectorAll('.multiSelect'));
appBar.sticky = false;
}