开发者

Preserving state when setting ItemsSource

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 Items开发者_开发问答Source, 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]


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.


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");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜