Using the Infragistics Control Persistence Framework with XamGrid

[Infragistics] Mihail Mateev / Tuesday, June 29, 2010

This article describes how to use the Infragistics Control Persistence Framework with XamGrid.

There are many cases when customers want to go back to the saved state of the application layout or to save the state of the Silverlight application when they close it and use it again next way when they start this application.

 Persistence Framework provides possibility to serialize and deserialize the state of the specified control or group of controls.

Most of Infragistics Line of Business and Microsoft Silverlight components works with the Control Persistence Framework. It is possible to control which of the component properties should be persistable and which shouldn't be.

For custom controls you need to maintain properties, which state will be saved or not implementing IProvidePropertyPersistenceSettings interface.

 public interface IProvidePropertyPersistenceSettings

{
       /// <summary>
       /// Gets a List of properties that shouldn't be saved when the PersistenceManager goes to save them.
       /// </summary>
       List<string> PropertiesToIgnore { get; }
 
       /// <summary>
       /// Gets a List of properties that should be applied, before even trying to look at any other property on the object.
        /// </summary>
        List<string> PriorityProperties { get; }
 
        /// <summary>
        /// Allows an object to perform an operation, after it's been loaded.
        /// </summary>
        void FinishedLoadingPersistence();
}

 

For property, that are ignored in this implementation you need to add a custom implementation of the persistence support.

This article demonstrates the mentioned above cases with the Infragistics Control Persistence Framework and XamGrid.

Demo application is based on created in the part 1 and part 2 of article "Using the Infragistics XamGrid and XamDataChart with Hierarchical Data and WCF RIA Services".

 In this application are used XamGrid and XamDataChart with WCF RIA Services. There is implementation of the XamGrid filtering.

When select specified bar from the chart

void XamDataChartSeriesMouseLeftButtonDown(object sender, Infragistics.Controls.Charts.DataChartMouseButtonEventArgs e)

{

    Customer customer = e.Item as Customer;

    if (customer == null)

    {

        return;

    }

 

    string value = customer.CustomerID;

 

    Shape x = e.OriginalSource as Shape;

    if (x != null)

    {

        _origBrush = x.Fill;

        _isChanged = true;

        x.Fill = new SolidColorBrush(Colors.Cyan);

    }

     Column col = customerXamGrid.Columns.DataColumns["CustomerID"];

    RowsFilter rf = new RowsFilter(typeof(string), col);

     if (ChkLowerFilter.IsChecked == true)

    {

        rf.Conditions.Add(new ComparisonCondition() { Operator = ComparisonOperator.GreaterThan, FilterValue = value});

    }

    else if (ChkUpperFilter.IsChecked == true)

    {

        rf.Conditions.Add(new ComparisonCondition() { Operator = ComparisonOperator.LessThan, FilterValue = value});

    }

    else

    {

        return;

    }

     customerXamGrid.FilteringSettings.RowFiltersCollection.Add(rf);

 }

 

In this sample will be added Persistence Framework support to save the XamGrid layout and filtering settings. XamGrid don't persist some of properties like Rows, ActiveCell, SelectedCells, SelectedRows. It persist XamGrid layout - position and sizes of the columns , visible rows etc.

Developers can still save these properties by adding them to the PropertySettings collection.

Requirements:

You need to install trial version of NetAdvantage for Silverlight Line of Business 10.2 . Demo sample includes also XamDataChart from  NetAdvantage for Silverlight Data Visualization 10.2 - it is not required when use an Infragistics Control Persistence Framework.

 

Create a Silverlight application with XamGrid and Persistence Framework:

  1. Create a Silverlight application, hosted in an ASP.Net application (demo application also uses WCF RIA Services).
  2. Create a Silverlight client with XamGrid and appropriate data (demo application data via RIA Services).
  3. Reference the InfragisticsSL4.Persistence.v10.2 assembly
  4.  Implement save and load functionalities for XamGrid settings
  5. Maintain additional controls with Persistence Framework via PersistenceGroup objects.

 Steps to create a Silverlight application are described in the in the part 1 and part 2 of article "Using the Infragistics XamGrid and XamDataChart with Hierarchical Data and WCF RIA Services".

  • Reference the InfragisticsSL4.Persistence.v10.2 assembly