locked
Checkboxes in Listbox get checked on random?! RRS feed

  • Question

  • Hi

    I Have following Listbox with a bunch of Checkboxes in it:

    <ListBox  ItemsSource="{Binding ElementName=map, Path=Layers.[0].Layers}" MinWidth="330" Margin="5" FontWeight="Normal">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                            <CheckBox Margin="2"
                                                Name="WasserhaltungMXD"
                                                Content="{Binding Name}" Tag="{Binding ID}"
                                                ClickMode="Press"/>
                                                <!--Click="CheckBox_Click2" IsChecked="{Binding DefaultVisibility}"/>-->
                                            </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>


    The Listbox is to large to fit into my Grid, so there is a Scrollbar. If i check a few Boxes and then use the Scrollbar, the checkboxes get unchecked, others get checked and so on. Its just chaos. But it doesnt happen each time. What could that be?? 

    Wednesday, September 8, 2010 6:52 AM

Answers

  • Try turning the virtualization off by using this:

    <ListBox.ItemsPanel>
        <ItemsPanelTemplate VirtualizingStackPanel.VirtualizationMode="Standard" />
    </ListBox.ItemsPanel> 

    Wednesday, September 8, 2010 8:16 AM

All replies

  • if the rows in your listbox are virtualized (i believe they are in SL3 and beyond), then the rows are reused and anything that isn't explicitly bound to some property will remain unchanged when the row is recycled.

    you should be able to fix this behavior by binding the checkboxes IsChecked property.  doesn't really matter if you actually use the property anywhere else, the row will just use it to remember what the checked state should be when it loads from being recycled.

    Wednesday, September 8, 2010 7:59 AM
  • Hmm iam not sure if i get this. ;)

    My IsChecked Event is bind although in post above its commented out. Or what do you mean by Binding the property? 

    Wednesday, September 8, 2010 8:09 AM
  • Try turning the virtualization off by using this:

    <ListBox.ItemsPanel>
        <ItemsPanelTemplate VirtualizingStackPanel.VirtualizationMode="Standard" />
    </ListBox.ItemsPanel> 

    Wednesday, September 8, 2010 8:16 AM
  • Jeah, i think that works! Thanks! 

    Wednesday, September 8, 2010 8:31 AM
  • Try turning the virtualization off by using this:

    <ListBox.ItemsPanel>
        <ItemsPanelTemplate VirtualizingStackPanel.VirtualizationMode="Standard" />
    </ListBox.ItemsPanel> 

    I had the same problem. Thanks so much.

    Monday, July 2, 2012 3:24 PM