Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

When placing Checkbox controls inside listbox they are... RSS

3 replies

Last post Mar 19, 2010 04:57 PM by gangtom

(0)
  • 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 02: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

  • Amanda Wang - MSFT

    Amanda Wang...

    All-Star

    17236 Points

    1466 Posts

    Microsoft

    Re: When placing Checkbox controls inside listbox they are randomly being checked when scrolling...

    Jul 31, 2009 09:23 AM | LINK

    Hi,

    We can reproduce your problem with your provided code.

    BUT if you place the  listbox control  in a ScollView contro can fix your problem. like below:

    <UserControl x:Class="childpage.listbox"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Width="400" Height="300">
        <Grid x:Name="LayoutRoot" Background="White">
            <ScrollViewer Width="100" Height="200">
            <ListBox x:Name="lstTest" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel x:Name="spTest" Orientation="Horizontal" >
                            <CheckBox x:Name="chkOne"/>
                            <CheckBox x:Name="chkTwo"/>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
    </ScrollViewer>
        </Grid>
    </UserControl>

    Amanda Wang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • LarryDev

    LarryDev

    Member

    77 Points

    86 Posts

    Re: When placing Checkbox controls inside listbox they are randomly being checked when scrolling...

    Jul 31, 2009 02:40 PM | LINK

    Amanda,

    Thank you so much.. That fixed the issue.. and by adding a Padding="0" in the ScrollViewer it makes it look just like a normal listbox on it's own.  Is this issue something that will be fixed in future updates of Silverlight because I believe others will run in to this?

    Thanks Again!

  • gangtom

    gangtom

    Member

    2 Points

    1 Post

    Re: When placing Checkbox controls inside listbox they are randomly being checked when scrolling...

    Mar 19, 2010 04:57 PM | LINK

    I'm facing the same problem with DataGridTemplateColumn with Checkbox as the DataTemplate.

     Any workaround for this problem, Amanda??