Enhancing Windows Presentation Foundation (WPF) XamDataGrid from Infragistics

Introduction

I had to extend the Infragistics Controls with added functionality and ease of use. And one of the primary goals I had to achieve was to abstract out the “Infragistics” touch from the controls. So as to look like an independent control. One of the most widely used controls of Infragistics, the “XamDataGrid” was missing some important features according to me. Remember, you are offered state-of-art control library, but with missing common stuff.

One of the most widely used controls of Infragistics , the “XamDataGrid” was missing some important features according to me. Remember, you are offered state-of-art control library, but with missing common stuff.

So this article will talk about extending the “XamDataGrid” control. This article would show only part of the features that I have added. In subsequent updates to this article, I will put the rest of the stuff in place.

The Infragistics library that this article uses is WPF 2008 Vol 2.


  • Infragistics3.Wpf.v8.2

  • Infragistics3.Wpf.Ribbon.v8.2

  • Infragistics3.Wpf.Editors.v8.2

  • Infragistics3.Wpf.Reporting.v8.2

  • Infragistics3.Wpf.DataPresenter.v8.2.dll

And the Infragistics2.Excel.v8.1 for exporting XamDataGrid to excel.

Let us first create a user control comprising the native DataPresenter’s XamDataGrid control.

The settings that are normally reused across all instances of XamDataGrid control in a project, are the:


  • FieldSettings Collection

  • FieldLayoutSettings Collection

  • Context Menus

  • Styles on the Grid

Let’s look at such a markup.


<igDP:XamDataGrid x_Class=”ReusableControls.XamDataGrid”
   
   xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
   xmlns:igDP=”http://infragistics.com/DataPresenter”
   xmlns:igRibbon=”http://infragistics.com/Ribbon”
   xmlns:igWindows=”http://infragistics.com/Windows”
   xmlns:igRep=”http://infragistics.com/Reporting”
   xmlns:igEditors=”http://infragistics.com/Editors”
   x:Name=”rxdg”  
   ContextMenuOpening=”xdg_ContextMenuOpening”
>
   <igDP:XamDataGrid.FieldSettings >
      <igDP:FieldSettings  
         AllowSummaries=”true”
         SummaryUIType=”MultiSelect”
         CellClickAction=”EnterEditModeIfAllowed”
         LabelTextAlignment=”Center”
         LabelTextTrimming=”WordEllipsis”
         LabelTextWrapping=”Wrap”>
</igDP:FieldSettings>
  </igDP:XamDataGrid.FieldSettings>

  <igDP:XamDataGrid.FieldLayoutSettings>
       <igDP:FieldLayoutSettings
                AllowFieldMoving=”WithinLogicalRow”
                HighlightAlternateRecords=”True”
                AllowAddNew=”False”
                AllowDelete=”True”
                SelectionTypeCell=”Default”
                MaxSelectedRecords=”1″
                SelectionTypeRecord=”Single”/>
       </igDP:FieldLayoutSettings>
   </igDP:XamDataGrid.FieldLayoutSettings>
   
   <igDP:XamDataGrid.Resources>
       <ContextMenu x_Key=”ugContextMenu” MenuItem.Click=”ugContextMenu_Click”  ButtonBase.Click=”ugContextMenu_Click”>
           <igRibbon:ButtonTool x_Name=”ButtonManageColumns”
                               Loaded=”ButtonManageColumns_Loaded”
                               >manage columns
           </igRibbon:ButtonTool>
           <igRibbon:ButtonTool x_Name=”ButtonClearGridPreferences”
                               Loaded=”ButtonClearGridPreferences_Loaded”
                               >clear grid preferences
           </igRibbon:ButtonTool>
           <igRibbon:ButtonTool x_Name=”ButtonExcelExporter”
                               Loaded=”ButtonExcelExporter_Loaded”
                               >xport 2 xcel
               </igRibbon:ButtonTool>
               <igRibbon:ButtonTool x_Name=”ButtonCSVExporter”
                               Loaded=”ButtonCSVExporter_Loaded”
                               >xport to csv
               </igRibbon:ButtonTool>
<igRibbon:ButtonTool x_Name=”ButtonXPSExporter”
                               VerticalAlignment=”Center”
                               Loaded=”ButtonXPSExporter_Loaded”
                               Click=”ButtonXPSExporter_Click”
                               >Export to XPS
               </igRibbon:ButtonTool>
               <igRibbon:ButtonTool x_Name=”ButtonPrintPreview”
                               VerticalAlignment=”Center”
                               Loaded=”ButtonPrintPreview_Loaded”
                               Click=”ButtonPrintPreview_Click”
                               >Print Preview
               </igRibbon:ButtonTool>
               <igRibbon:ButtonTool x_Name=”ButtonPrint”
                               VerticalAlignment=”Center”
                               Loaded=”ButtonPrint_Loaded”
                               Click=”ButtonPrint_Click”
                               >Print
               </igRibbon:ButtonTool>
              
       </ContextMenu>
       <Style TargetType=”{x:Type igDP:HeaderLabelArea}”>
           <Setter Property=”ContextMenu” Value=”{StaticResource ugContextMenu}” />
       </Style>
   </igDP:XamDataGrid.Resources>
</igDP:XamDataGrid>


The key properties are the

FieldSettings:

   LabelTextAlignment, LabelTextTrimming, LabelTextWrapping

FieldLayoutSettings:

   AllowFieldMoving, HighlightAlternateRecords,AllowAddNew,

   AllowDelete, MaxSelectedRecords

And adding Context menu to the grid. The context menu is loaded with buttons like Export to CSV, Export to Excel, and Export to XPS, Print, Print Preview and clear Grid Preferences.

Note: This code blocks for the Context menu functionalities are taken from Infragistics samples.

More by Author

Must Read