设置 ItemsSource 时保留状态
我有一个代理类型为 {警察、消防、紧急情况} 的列表框 (ListBox1),
当用户选择代理类型时,通过设置项目源,将使用 (名称、复选框) 填充另一个列表框 (ListBox2)。
问题是,如果我选择“警察”,然后选中一个复选框,然后选择“火灾”,然后再次选择“警察”,复选框状态就会丢失。我知道 CheckBox 状态丢失,因为我正在重置 ItemsSource,但我想知道解决此问题的正确方法是什么。
ListBox1
[Police] is selected
[Fire]
[Emergency]
ListBox2
[ Name, CheckBox for Police agency 1]
[ Name, CheckBox for Police agency 2]
[ Name, CheckBox for Police agency 3]
I have a ListBox (ListBox1) of Agency types {Police, Fire, Emergency}
When the user selects an Agency type, Another ListBox (ListBox2) is populated with (Name, CheckBox) by setting the items source.
The problem is if I select Police, then check a CheckBox, then select Fire, and select Police again, the CheckBox state is lost. I know the CheckBox state is lost because I'm resetting ItemsSource, but I'm wondering what's the correct way to go about this.
ListBox1
[Police] is selected
[Fire]
[Emergency]
ListBox2
[ Name, CheckBox for Police agency 1]
[ Name, CheckBox for Police agency 2]
[ Name, CheckBox for Police agency 3]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该在视图模型中检查状态。第一个列表框模型应该有一个代理集合,每个代理模型都有一个用于复选框的布尔值。因此,只需将其绑定到视图,它就会保留。
You should have the status checked in your viewmodel. The first listbox model should have a collection of agency, ad each agency model have a bool for the checkbox. So just bind that to the view and it will preserve.
我会在母标签中执行 setAttribute("hide") = currentValue (只允许确保命名的唯一性) onblur ListBox1
...并且 - onfocus 我会 getElementById("").getAttribute("hide");
I would do a setAttribute("hide") = currentValue in the mother TAG (allowed just ensure uniqueness in naming) onblur ListBox1
...and - onfocus I would getElementById("").getAttribute("hide");