Infosys Microsoft Alliance and Solutions blog

« Webinar - Modernizing from Mainframes to Next-generation IT Systems | Main | Silverlight - Are you missing WatermarkedTextBox? »

Silverlight - CheckBox issue when in ListBox

Recently for an application I was building on Silverlight 2.0 Beta 2, I had a need to use CheckBox inside the ListBox. Getting the CheckBox into the ListBox item was fairly trivial via the DataTemplate. However the problem started after that.

I could click on the first CheckBox, but when I tried to click on any in the remaining rows, the click won't work. I could easily see the hover effect over the CheckBox so wasn't sure why the click had issues.

See here the code I was using (minimum code to reproduce this issue). 

Code behind

namespace SilverlightApplication1


    public partial class Page : UserControl


        public Page()






    public class Frameworks: List<string>


        public Frameworks()


            this.Add(".NET 1.1");

            this.Add(".NET 2.0");

            this.Add(".NET 3.0");

            this.Add(".NET 3.5");





<UserControl x:Class="SilverlightApplication1.Page"




   Width="400" Height="300">


        <local:Frameworks x:Key="fwks" />


    <Grid x:Name="LayoutRoot" Background="White">

        <ListBox HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="51,26,192,71" ItemsSource="{StaticResource fwks}">



                    <CheckBox Content="{Binding}"/>







The following picture shows how this simple application looked at runtime.  


I initially suspected if ZIndex had anything to do with it, but the hover effected worked fine. It turns out there is some issue in the way ListBox handles it focus. In this application, If I first select a ListBox item, but clicking towards the right side of the item and then click on the CheckBox it works fine.

The workaround to this issue is to change the default ClickMode behavior of CheckBox. By default it is set to Release. This means that the Click fires when the mouse button is first pressed and then released over the control. Due to ListBox taking focus in between, the click never get's completed on the CheckBox and thus the state doesn't change to Checked.

By setting the ClickMode to Press, things work fine. The modified XAML will be as below.


    <CheckBox Content="{Binding}" ClickMode="Press" />


I also found this solution as part of one of the questions on the Silverlight forum. 

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Please key in the two words you see in the box to validate your identity as an authentic user and reduce spam.

Subscribe to this blog's feed

Follow us on

Blogger Profiles

Infosys on Twitter