views:

464

answers:

4

Hello, I want to use LoadingRowGroup event in SilverLight DataGrid to display a group summary.

I have an event:

void dataGrid1_LoadingRowGroup(object sender, DataGridRowGroupHeaderEventArgs e)
{                        
    // e.RowGroupHeader
}

but I don't know how to use e.RowGroupHeader to set group header value. Maybe I should use e.RowGroupHeader.Template, but I don't know how to set a template by code.

A: 

Since nobody has helped me, I found a solution by myself :)

In fact there are two ways:
1) by using LoadingRowGroup event in DataGrid:

 void dataGrid1_LoadingRowGroup(object sender, DataGridRowGroupHeaderEventArgs e)
 {
      e.RowGroupHeader.Template = (ControlTemplate)System.Windows.Markup.XamlReader.Load(
           @"<ControlTemplate xmlns=""http://schemas.microsoft.com/client/2007""&gt;
                    <StackPanel Orientation=""Horizontal"" Background=""LightGray"">
                        <TextBlock Text=""Name of group: "" HorizontalAlignment=""Left""/>
                        <TextBlock Text=""{Binding Name}"" HorizontalAlignment=""Left""/>
                    </StackPanel>
           </ControlTemplate>");
 }

2) By setting a Style of DataGridRowGroupHeader:

    <data:DataGrid.RowGroupHeaderStyles>
            <Style TargetType="data:DataGridRowGroupHeader">
                <Setter Property="SublevelIndent" Value="0" />
                <Setter Property="Height" Value="30" />
                <Setter Property="IsEnabled" Value="false" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <StackPanel Orientation="Horizontal" Background="LightGray">
                                <TextBlock Text="Name of group: " HorizontalAlignment="Left"/>
                                <TextBlock Text="{Binding Name}" HorizontalAlignment="Left"/>                                                                                                    
                            </StackPanel>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>                    
            </Style>
    </data:DataGrid.RowGroupHeaderStyles>

The (2) way is better for static elements. But the first one can be used when you want to generate headers in a more dynamic way.

A: 

This code is not working. I mean "{Binding Name}" is not working

Jagz
DataGridRowGroupHeader has the "Name" property, so I don't know where could be a mistake. My code works with Silverlight 3.0.
A: 

This code is working with sl4. thanks nandrew...

llo
A: 

but it can't show the items in the end! like: group name: name(6 items)

rooshan