WP7列表框-清除所选项目
我在数据模板中使用列表框 - 从之前的帖子中我无法直接在后面的代码中引用列表框。
因此,我捕获列表框的 SelectionChanged 事件中最后选定的对象,并在我想要导航时使用它。
我现在还需要清除列表框中选定的对象 - 我可以在 SelectionChanged 事件中执行此操作(在将其存储之后)。
或者,我可以在列表框中使用 MouseLeftButtonDown 事件(我理解这相当于“单击”),但我可以在此事件中获取列表框中的选定对象吗?
- 谢谢
I am using a listbox in a data template - and from an earlier post I cannot reference the listbox directly in the code behind.
As a result I am capturing the last selected object in the selectionchanged event for the listbox and using this when I want to navigate.
I now need to also clear the selected object in the listbox -can I do this in the selectionchanged event (after storing it away).
Alternatively I could use the MouseLeftButtonDown event on the listbox (which I understand is the equivalent of a 'click') but can I get the selected object in the listbox in this event.
- thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在选择更改事件中设置.SelectedIndex = -1;
另外,不要使用 MouseLeftButtonDown 事件。每当用户触摸列表框时,即使他们只是尝试向上/向下滚动而不是实际选择某个项目,这都会触发。
In the selection changed event set
<ListboxName>.SelectedIndex = -1;
Also, do not use the MouseLeftButtonDown event. This will fire whenever the user touches the ListBox, even if they're just trying to scroll up / down and not actually selecting an item.
如果您无法在后面的代码中更改 SelectedIndex,则可以检测 ListBoxItem 上的
Tap
事件,而不是检测 SelectionChanged 事件。If you can't change the SelectedIndex in code behind then, instead of detecting the SelectionChanged event you could detect a
Tap
event on the ListBoxItem.