/default.aspx
Silverlight .NET CMS and Controls
Home
/controls.aspx
Silverlight Controls
Controls
CheckBox

Silverlight CheckBox Control

The Liquid Controls CheckBoxPlus control has been removed from the library from version 4.8 onwards. This is because the functionality of the checkbox can be easily replicated using the standard checkbox that ships with Silverlight 2 and helps reduce the overall size of the Liquid Controls DLL.

How to Use the CheckBox Control

To use the checkbox on your Silverlight page:

<UserControl x:Class="Checkbox_Test.Page"
    xmlns="http://schemas.microsoft.com/client/2007"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="400" Height="300">
     <Canvas>
          <CheckBox x:Name="testCheckBox" Canvas.Left="10" Canvas.Top="0" Content="This is a checkbox" Click="testCheckBox_Click" />
          <CheckBox x:Name="testCheckBox2" Canvas.Left="10" Canvas.Top="20" Content="This is another checkbox" />
     </Canvas>
</UserControl>

 

In your C# code behind file you can refer to the CheckBox using testCheckBox. The Silverlight CheckBox has a Checked property which allows you to toggle the checked state, if you do not hook into this event then the CheckBox will toggle itself, however if you wish to override this event you must perform the toggle in addition to any custom code preformed.

The CheckBox exposes a click event which is fired (named Clicked) when the control is clicked on, you can attach an event handler to this to perform custom actions.

using System;
using System.Collections.Generic;
using System.Linq;
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 Checkbox_Test
{
     public partial class Page : UserControl
     {
          public Page()
          {
               InitializeComponent();
          }

          void testCheckBox_Click(object sender, RoutedEventArgs e)
          {
               // To handle check changed
          }
     }
}

 

Your Comments and Questions Answered

 You are not logged in. You need to login to post new messages, if you do not have a login you can register for free!

dan Feb, 27 2008 - 03:59

Hello,

This is in fact the intended behaviour. In the earlier versions 2.x, the line in the event handler:

this.cbActive.Checked ^= true;

Was required. In version 3.0 this is handled by the control, so in your code you do not need to handle the Clicked() event unless you are doing specific processing at the clicked stage. The checkbox will automatically update itself when it is clicked. Apologies for not mentioning this, it looks like it got missed off the release notes. Let me know if you need any more information about this change.

 

ajayb Feb, 27 2008 - 03:37

Looks like there is a bug in the code for the CheckBox. Here if I add some code say for e.g.
Initializer
this.cbActive.Clicked += new EventHandler(cbActive_Clicked);
this.cbActive.Checked = true;

and in the event handler
void cbActive_Clicked(object sender, EventArgs e)
{
this.cbActive.Checked ^= true;
}

this will always give true (The initial value of the checkbox and the UI remains unchanged.) If I comment out the code in the event handler, the Ui reflects the changed status of the checkbox.
Is there a fix due?

 

dan Feb, 14 2008 - 04:22

Hello,

In Version 2.7 the checkbox is a Rectange, as you rightly point out, having it as an Elipse limited it's style-ability. Now it is a Rectangle, through the use of the skinning method, gives you complete control of how rounded the edges are.

 

prejeshvp Feb, 14 2008 - 02:26


Hi DAN,
Can we change structure of the checkbox from ellipse to square

 
This page is 20.98KB and was generated by the SilverPages CMS in 0.031 seconds. Total impressions: 625.