XAML:
<DataGrid x:Name="dg">
<DataGrid.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="Test"/>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</DataGrid.GroupStyle>
<DataGrid.Resources>
<Style x:Key="myStyle" TargetType="CheckBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="CheckBox">
<RadioButton IsChecked="{Binding IsChecked, Mode=TwoWay, RelativeSource={RelativeSource AncestorType=CheckBox}}"
Content="{TemplateBinding Content}"
GroupName="{Binding MyProperty}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridCheckBoxColumn ElementStyle="{StaticResource myStyle}"
EditingElementStyle="{StaticResource myStyle}"
IsReadOnly="False"
Binding="{Binding Flag, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Header="1"/>
</DataGrid.Columns>
</DataGrid>
Code-Behind:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
object[] items = new object[] {
new MyClass() { Flag = false, MyProperty = 1 },
new MyClass() { Flag = false, MyProperty = 1 },
new MyClass() { Flag = false, MyProperty = 1 },
new MyClass() { Flag = false, MyProperty = 1 },
new MyClass() { Flag = false, MyProperty = 1 },
new MyClass() { Flag = false, MyProperty = 2 },
new MyClass() { Flag = true, MyProperty = 2 },
new MyClass() { Flag = false, MyProperty = 2 },
};
ICollectionView cv = CollectionViewSource.GetDefaultView(items);
cv.GroupDescriptions.Add(new PropertyGroupDescription("MyProperty"));
this.dg.ItemsSource = cv;
}
public class MyClass : INotifyPropertyChanged
{
public int MyProperty { get; set; }
private bool flag;
public bool Flag
{
get { return this.flag; }
set
{
this.flag = value;
this.OnPropertyChanged("Flag");
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
#endregion
}
}