Click here to Skip to main content
12,997,166 members (68,594 online)
Click here to Skip to main content
Add your own
alternative version


4 bookmarked
Posted 4 Apr 2012

Making a simple RadioList with CheckBoxes

, 4 Apr 2012
Rate this:
Please Sign up or sign in to vote.
How to make/use a simple RadioList displaying an "n" state value with checkboxes.


Here is a nice Tip on how to make/use a simple RadioList displaying an "n" state value with checkboxes. 

Using the code 

Ok!-So because we need a radio list filled with checkboxes we need to define a custom RadiobuttonList Item. The targeted control for the Control Template should be set to ListBoxItem

<Style x:Key="CustomRadioButtonListItem" TargetType="{x:Type ListBoxItem}" >
	<Setter Property="SnapsToDevicePixels" Value="true"/>
	<Setter Property="OverridesDefaultStyle" Value="true"/>
	<Setter Property="Template">
			<ControlTemplate TargetType="{x:Type ListBoxItem}"> 

Following a Grid content must be defined so that it contains the checkbox:

<Grid Width="13" Height="13" >
<CheckBox IsChecked="{TemplateBinding IsSelected}" />

Add some content presenter nice props ..  



        Content             = "{TemplateBinding ContentControl.Content}"

        ContentTemplate     = "{TemplateBinding ContentControl.ContentTemplate}"

        ContentStringFormat = "{TemplateBinding ContentControl.ContentStringFormat}"

        HorizontalAlignment = "{TemplateBinding Control.HorizontalContentAlignment}"

        VerticalAlignment   = "{TemplateBinding Control.VerticalContentAlignment}"

        SnapsToDevicePixels = "{TemplateBinding UIElement.SnapsToDevicePixels}" />

Set the ItemContainerStyle prop of the ListBox to support the new RadiobuttonlistItem:

<Style x:Key="CustomRadioButtonList" TargetType="ListBox">
	<Setter Property="ItemContainerStyle" Value="{StaticResource RadioButtonListItem}" />

.. and that's it.

Take care now only to override the style of your ListBox control when needed.

Points of Interest

So did I learn anything interesting/fun/annoying while writing the code? :)

Yep- pretty fun working with styles after I've got my way in the concept, but until then many "Why is that happening? It makes no sense!" thoughts crossed my mind. But it  pays off as styles are very useful when designing custom applications and as we already know could prove key when clients do want to buy. 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Adrian Calinciuc
Software Developer Yonder
Romania Romania
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170622.1 | Last Updated 4 Apr 2012
Article Copyright 2012 by Adrian Calinciuc
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid