Hi,
I am trying to group items in a datagrid based on a particular property, I am not able to see the group header text. I have given below the Xaml part, ViewModel & Model. Looking forward for help.
Regards,
Ramakrishna
Xaml code:
<DataGrid ItemsSource="{Binding GroupView}" AutoGenerateColumns="False">
<DataGrid.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=Subject}"
/>
</StackPanel>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type
GroupItem}">
<Expander>
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Subject}" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</DataGrid.GroupStyle>
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="File" Binding="{Binding IsChecked}"/>
<DataGridTextColumn Header="Attachment Name" Binding="{Binding OriginalName}"/>
<DataGridTextColumn Header="Filing Attachment Name" Binding="{Binding FinalName}"/>
<DataGridTextColumn Header="Location" Binding="{Binding Location}"/>
<DataGridTextColumn Header="Subject" Binding="{Binding Subject}"/>
</DataGrid.Columns>
</DataGrid>
ViewModel Code:
public class AttachmentViewModel : INotifyPropertyChanged
{
Private ListCollectionView view;
public AttachmentViewModel()
{
ObservableCollection<AttachmentItem> items = new ObservableCollection<AttachmentItem>();
AttachmentItem item = new AttachmentItem(true, @"C:\Users\ram.devarakonda\Desktop\Me", "Me-14-05-2013", @"C:\Users\ram.devarakonda\Desktop", "Mysubject");
AttachmentItem item1 = new AttachmentItem(false, @"C:\Users\ram.devarakonda\Desktop\He", "He-14-05-2013", @"C:\Users\ram.devarakonda\Desktop", "HeySubject");
items.Add(item);
items.Add(item1);
GroupView = new ListCollectionView(items);
GroupView.GroupDescriptions.Add(new PropertyGroupDescription("Subject"));
}
public ListCollectionView GroupView
{
get
{
return view;
}
set
{
this.view = value;
this.OnPropertyChanged("GroupView");
}
}
}
Model Code:
public class AttachmentItem : INotifyPropertyChanged
{
private bool ischecked;
private string subject;
private string originalName;
private string finalName;
private string location;
public AttachmentItem(bool ischecked, string originalName, string finalName, string location, string subject)
{
this.Ischecked= ischecked;
this.Subject = subject;
this.OriginalName= originalName;
this.FinalName= finalName;
this.Location = location;
}
public bool Ischecked
{
get
{
return this.ischecked;
}
set
{
this.ischecked= value;
this.OnPropertyChanged("Ischecked");
}
}
public string Subject
{
get
{
return this.subject;
}
set
{
this.subject = value;
this.OnPropertyChanged("Subject");
}
}
public string OriginalName
{
get
{
return this.originalName;
}
set
{
this.originalName= value;
this.OnPropertyChanged("OriginalName");
}
}
public string FinalName
{
get
{
return this.finalName;
}
set
{
this.finalName= value;
this.OnPropertyChanged("FinalName");
}
}
public string Location
{
get
{
return this.location;
}
set
{
this.location = value;
this.OnPropertyChanged("Location");
}
}
}
Ramakrishna