Grouping and Checkboxes in WPF

What I wanted was the check / uncheck behavior of checkbox (really of the base toggle button) with the mutual exclusivity behavior of a radio button.

C# (35.2 KB)
 
 
 
 
 
(0)
3,535 times
Add to favorites
3/12/2011
E-mail Twitter del.icio.us Digg Facebook
<Window x:Class="GroupingCheckboxes.Window1"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		Title="Window1"
		xmlns:GroupingToggleButtons="clr-namespace:GroupingToggleButtons"
		Height="300"
		Width="300">
	
	<StackPanel>

		<StackPanel Orientation="Horizontal">
			<CheckBox GroupingToggleButtons:ToggleButtonExtensions.GroupName="Group1"
					  Content="1" />
			<CheckBox GroupingToggleButtons:ToggleButtonExtensions.GroupName="Group1"
					  Content="2" />
			<CheckBox GroupingToggleButtons:ToggleButtonExtensions.GroupName="Group1"
					  Content="3" />
			<CheckBox GroupingToggleButtons:ToggleButtonExtensions.GroupName="Group1"
					  Content="4" />
			<CheckBox GroupingToggleButtons:ToggleButtonExtensions.GroupName="Group1"
					  Content="5" />
		</StackPanel>


		<StackPanel Orientation="Horizontal">
			<CheckBox GroupingToggleButtons:ToggleButtonExtensions.GroupName="Group2"
					  Content="6"
					  x:Name="Group2Box1" />
			<CheckBox GroupingToggleButtons:ToggleButtonExtensions.GroupName="Group2"
					  Content="7"
					  x:Name="Group2Box2" />
		</StackPanel>
		
		<StackPanel Orientation="Horizontal">
			<CheckBox GroupingToggleButtons:ToggleButtonExtensions.GroupName="Group3"
					  Content="8" />
		</StackPanel>
		
		
		<Button Content="Change Group Names"
				Click="Button_Click" />


		<Button Content="UnGroup"
				Click="UnGroupButton_Click" />

		
	</StackPanel>
</Window>