开发者

Silverlight ListBox triggering CheckBox events when scrolled

I've got a list box where the items are check boxes. When the list box is scrolled I am finding that the Checked and Unchecked events are firing for items as they either scroll into view or scroll out of view.

It seems related to what this post discusses:

Silverlight 3 Checkbox Listbox bug when scrolling?

The problem I have is the events firing, because I am updating data on the server when this happens. So I get all this spurious server comms when I only want it to happen when the user changes the state of the check box.

Is there some way to stop this event firing when开发者_如何转开发 scrolling?


So I get all this spurious server comms when I only want it to happen when the user changes the state of the check box.

I don't think the Checked and Unchecked events are fit for the purpose you are putting them to. They were really designed to affect visual state. Instead you should be binding a boolean property on on listed item object to the IsChecked property of the Checkbox. Code in the setter in the item object can then kick off the server stuff (for belts and braces it could compare current value with incoming value).

To answer your question you might try specifying plain old StackPanel in the template for the ItemsPanel property of the list box. Although this might not be an option if you a lot of entries.


The default ItemsPanel of the ListBox is the VirtualizingStackPanel. You can change it to use the StackPanel, this way your problem is solved. Use this code:

<ListBox.ItemsPanel>
  <ItemsPanelTemplate>
     <StackPanel />
  </ItemsPanelTemplate>
<ListBox.ItemsPanel>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜