惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
阮一峰的网络日志
阮一峰的网络日志
云风的 BLOG
云风的 BLOG
D
Docker
Vercel News
Vercel News
IT之家
IT之家
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
腾讯CDC
Google DeepMind News
Google DeepMind News
I
InfoQ
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
博客园 - Franky
The Cloudflare Blog
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
T
Tenable Blog
P
Proofpoint News Feed
Recorded Future
Recorded Future
Security Latest
Security Latest
H
Hackread – Cybersecurity News, Data Breaches, AI and More
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 聂微东
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google Online Security Blog
Google Online Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
U
Unit 42
The Hacker News
The Hacker News
Martin Fowler
Martin Fowler
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
F
Full Disclosure
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
Project Zero
Project Zero

博客园 - 黎波

精至手机药典Windows Phone 7版 [WP7]修改 Pivot 控件的 PivotItem 标题字体大小 [WP7]CheckBox 文字自动换行 Windows Phone 7 系统主题颜色RGB和Hex值 [WP7]MD5加密字符串 [iOS]MD5加密字符串 [Android]MD5加密字符串 [Android]获取设备IP地址 如何检查对象的类型[iOS/Android/Windows Phone] 精至手机药典iPhone版 [iOS]NSString常用代码 目标身高iPhone版 目标身高Android版 [iOS]让Xcode 4.2生成的app支持老的iOS设备(armv6) [iOS]升级到 Xcode 4.1 后 sqlite3.h 引起 Expected declaration specifiers before 'interface' 错误 [转载]用手机玩转汽车 体验安吉星手机应用程序 [iOS]Xcode 4.1 bug: Text Field 引起 EXC_BAD_ACCESS 错误的解决 精至手机药典Android版 [Android]使用ProGuard遇到“conversion to Dalvik format failed with error 1”错误的解决办法
[WP7]关于 ListBox 的 SelectionChanged 事件
黎波 · 2012-06-25 · via 博客园 - 黎波

问题描述:在使用 ListBox 的 SelectionChanged 事件时,可能会遇到一个小问题,就是当重复选中同一个 Item 时,SelectionChanged 事件只是在第一次选中 Item 时触发,我们期望的是每次都能触发。

原因分析:原因很简单,ListBox 列表框里面的 Item 被选中后,ListBox 的 SelectedIndex 会被设置为该 Item 的 Index,当第二次选中这个 Item 时,事实上 SelectedIndex 并没有变,因此 SelectionChanged 事件也不会被触发,从事件的名称上理解也应该如此。

解决思路:为了达到我们期望的效果,只需要在 SelectionChanged 事件处理方法中将 ListBox.SelectedIndex 设置为 -1,即没有选中任何 Item。

示例代码: 

private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)  
{  
    // If selected index is -1 (no selection) do nothing  
    if (listBox.SelectedIndex == -1)  
        return;  
 
    // Navigate to the new page  // Reset selected index to -1 (no selection)  
    listBox.SelectedIndex = -1;              
}

参考:http://forums.create.msdn.com/forums/p/66377/406079.aspx#406079

作者:黎波
博客:http://bobli.cnblogs.com/
日期:2012年6月25日