Click here to Skip to main content
Click here to Skip to main content

Making a simple RadioList with CheckBoxes

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

Introduction

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">
		<Setter.Value>
			<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}" />
</Grid> 

Add some content presenter nice props ..  

<ContentPresenter
	RecognizesAccessKey="True"
        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}" />
</Style> 

.. 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? Smile | :)

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. 

License

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

Share

About the Author

Adrian Calinciuc
Software Developer Yonder
Romania Romania
No Biography provided

Comments and Discussions

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