Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

  • LarryDev

    LarryDev

    Member

    77 Points

    86 Posts

    When placing Checkbox controls inside listbox they are randomly being checked when scrolling up a...

    Jul 25, 2009 01:04 PM | LINK

    I originally posted this in the controls forum and have gotten no responses.  But I do believe this is an actual bug in Silverlight 3 and I need to know how to get this fixed.  I would appreciate it if someone could even just try my code in their environment and confirm if you are having the same thing happen.  Also if someone has a Silverlight 2 environment and can test if this problem existed in Silverlight 2.

    Original Post:

    I am trying to code a listbox in Silverlight 3 (released version) and am having issues with placing two checkboxes inside of a list.  I have created a simple example to demonstrate my issue.  In my example I create 50 rows of two checkboxes.  When I run the project I can check the 2nd and 3rd rows left checkboxes.  Then if I grab the listboxes scroll bar and scroll down to the bottom and back up again I am fine if I scroll slowly.  But if I grab the scroll bar and quickly go up and down or if I use the up and down arrows on the scroll bar by just holding my left mouse button down on it I will find random other checkboxes selected.  Has anyone else run in to this issue and does anyone have a solution?  Thank You!

    Here is my sample code:

    MainPage.xaml

    <UserControl x:Class="CheckBoxIssueCSharp.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
        <Grid x:Name="LayoutRoot">
            <ListBox x:Name="lstTest" Width="100" Height="200">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel x:Name="spTest" Orientation="Horizontal">
                            <CheckBox x:Name="chkOne"/>
                            <CheckBox x:Name="chkTwo"/>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
    </UserControl>
    
       

    MainPage.xaml.cs 

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    
    namespace CheckBoxIssueCSharp
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
                for (int n = 0; n <= 51; n++) 
                { 
                    lstTest.Items.Add("");
                }
            }
        }
    }
    
       

    bug report listBoxbox silverlight 3