Styling the GroupByArea in xamDataPresenter

Glossary Item Box

Infragistics(R) NetAdvantage(R) for WPF

Styling the GroupByArea in xamDataPresenter

You can style xamDataPresenter's™ GroupBy area by overriding the GroupByArea template. A common scenario of when you would override the GroupByArea template is when a GroupBy has been performed in code and cannot be modified by the end user.

The following procedure assumes you have a data bound xamDataPresenter, and you want to customize look of the GroupByArea. For more information, see Creating xamDataPresenter in XAML.

  1. Define the GroupBy area's style in the Grid's Resource section. The following XAML demonstrates a simple GroupByArea template containing a text box.

    In XAML:

    	...
    	<Style x:Key="MyCustomGroupByArea" TargetType="igDP:GroupByArea">
    		<Setter Property="Template">
    			<Setter.Value>
    				<ControlTemplate TargetType="igDP:GroupByArea">
    					<TextBlock>The data has been grouped by 
    					  Product Name, and cannot be changed 
    					  at run time.</TextBlock>
    				</ControlTemplate>
    			</Setter.Value>
    		</Setter>
    	</Style>
    </Grid.Resources>
    

  2. The following XAML creates an instance of XamDataPresenter and names it. The XAML then sets the GroupByAreaStyle to the static resource created in the Grid's Resource section.

    In XAML:

    <igDP:XamDataPresenter x:Name="XamDataPresenter1" 
      ...
      GroupByAreaStyle="{StaticResource MyCustomGroupByArea}"/>
    

  3. In the Page or Window opening tag, set the Loaded property to the Samp_Loaded method which is defined in the next step. This  method is called when the Page or Window is loaded and will specify the custom GroupBy code.

    In XAML:

    Loaded="Samp_Loaded"
  4. The following code defines the method referenced in the previous step. The method creates a FieldSortDescription and assigns the FieldName to the Field you are grouping by. The method then specifies the Direction the GroupBy should be performed. The method then turns the GroupBy functionality on by setting the IsGroupBy property to True. Add the newly created FieldSortDescription to xamDataPresenter's FieldLayouts SortedFields

    In Visual Basic:

    Imports System.ComponentModel
    Imports Infragistics.Windows.DataPresenter
    ...
    Sub Samp_Loaded(ByVal o As Object, ByVal e As RoutedEventArgs)
    	Dim sd As New FieldSortDescription()
    	sd.FieldName = "ProductName"
    	sd.Direction = ListSortDirection.Ascending
    	sd.IsGroupBy = True
    	Me.XamDataPresenter1.FieldLayouts(0).SortedFields.Add(sd)
    End Sub
    

    In C#:

    using System.ComponentModel;
    using Infragistics.Windows.DataPresenter;
    ...
    void Samp_Loaded(object o, RoutedEventArgs e)
    {
    	FieldSortDescription sd = new FieldSortDescription();
    	sd.FieldName = "ProductName";
    	sd.Direction = ListSortDirection.Ascending;
    	sd.IsGroupBy = true;
    	this.XamDataPresenter1.FieldLayouts[0].SortedFields.Add(sd);
    }
    

  5. Build and run the project. You should see xamDataPresenter sorting by ProductName with a custom message in the GroupBy area similar to the image below.

E-mail your feedback on this topic.

Opinion about our help? Take our survey.

Copyright © 2003-2007 Infragistics, Inc. All rights reserved.

Build Version: 7.1.20071.1320