Basic Information:Here is some information on setting some basic persistence settings on the xamGrid. If you have additional info that would be useful please add to this discussion.
References (Developer Guide-> Infragistics Control Persistence Framework):http://help.infragistics.com/Doc/Silverlight/2011.2/CLR4.0/Out of the box the persistence framework is extremely useful and saved us from countless hours of work and design. The settings are serialized to xml and easily compatible with streams. You can save and load settings from single or multiple controls into a settings group. You can easily reset settings to a default control state, or some other control state. After testing this it also works now with dynamic objects and dynamic data sources (meaning I can clear my settings and load new data or a new data source into a grid and save or load new persistence settings for the grid). There are also some good examples in the online documentation on how to get started.
Determining Which Properties to Save
It will automatically save/load all properties of the control or only the ones you specify. This really helps when you need to be concious of space and only need a handful of settings loaded or saved.
To give you an idea on the size comparison, here is the result using a grid with 5 columns:All Grid Properties: 933 KBOnly Specified: 11kb (1 property)XAML for specifying some settings and properties is listed below:
<ig:XamGrid><ig:PersistenceManager.Settings><ig:PersistenceSettings SavePersistenceOptions="OnlySpecified" LoadPersistenceOptions="AllButIgnored">
<ig:PropertyNamePersistenceInfo PropertyName="ColumnResizingSettings"/>
Its really that simple to setup. To save or load its even easier:Save persistence settings for a datagrid:
using System.IO;using Infragistics.Persistence;MemoryStream ms = new MemoryStream();ms = PersistenceManager.Save(grid);
Now you have a stream and can save to whatever store you want. Want a string you can look at, store, or print to a file quick?
var sr = new StreamReader(ms); var myStr = sr.ReadToEnd();
Another nice thing about specifying properties is that you can do it in XAML or Code, and you can override settings from XAML in Code.Code for settings:
PersistenceSettings settings = new PersistenceSettings(); settings.SavePersistenceOptions = PersistenceOption.OnlySpecified; PropertyNamePersistenceInfo prop = new PropertyNamePersistenceInfo(); prop.PropertyName = "ColumnMovingSettings"; settings.PropertySettings.Add(prop); // Save with specified settings
XamGrid grid = devGrid as XamGrid; ms = new MemoryStream(); ms = PersistenceManager.Save(devGrid, settings);
Load Persistence From Stream:
MemoryStream ms = stream; PersistenceManager.Load(grid, ms);
Load Persistence From Stream with Specific settings:
PersistenceSettings settings = new PersistenceSettings(); settings.LoadPersistenceOptions = PersistenceOption.OnlySpecified; // Add properties here// Load stream with settings specifiedPersistenceManager.Load(grid, ms, settings);
What properties?
With all the properties available in the grid you might think it would take a while to figure out which ones you want to use if your going to specify them. Fortunately it was easier than I thought to store the properties I was interested in. I managed to specify column size, column order, sorting, grouping, columns hidden/shown, and filter settings, all with the lines below.
I ended up using the following properties:
<ig:PersistenceSettings SavePersistenceOptions="OnlySpecified" LoadPersistenceOptions="OnlySpecified"> <ig:PersistenceSettings.PropertySettings>
<ig:PropertyNamePersistenceInfo PropertyName="ColumnResizingSettings"/> <ig:PropertyNamePersistenceInfo PropertyName="ColumnMovingSettings"/> <ig:PropertyNamePersistenceInfo PropertyName="SortingSettings"/> <ig:PropertyNamePersistenceInfo PropertyName="ColumnChooserSettings"/> <ig:PropertyNamePersistenceInfo PropertyName="GroupBySettings" Options="Contains"/> <ig:PropertyNamePersistenceInfo PropertyName="Columns[].FilterColumnSettings" Options="Contains"/>
So this doesn't work for me I get a stack overflow error everytime i try this.
<ig:PersistenceManager.Settings><ig:PersistenceSettings SavePersistenceOptions="OnlySpecified" LoadPersistenceOptions="OnlySpecified">
<ig:PersistenceSettings.PropertySettings>
<ig:PropertyNamePersistenceInfo PropertyName="ColumnMovingSettings"/>
<ig:PropertyNamePersistenceInfo PropertyName="SortingSettings"/>
<ig:PropertyNamePersistenceInfo PropertyName="ColumnChooserSettings"/>
<ig:PropertyNamePersistenceInfo PropertyName="GroupBySettings" Options="Contains"/>
<ig:PropertyNamePersistenceInfo PropertyName="Columns[].FilterColumnSettings" Options="Contains"/>
</ig:PersistenceSettings.PropertySettings>
</ig:PersistenceSettings> </ig:PersistenceManager.Settings>
I am using two button one to save and one to load the settings. it saves fine in my viewmodel property. but when loading i always get a stack over flow exception and i dont know why
Hello beagle77,
I am not sure what may cause this behavior on your side. Would you please provide me with a small sample where this issue is reproducible so I can investigate it further.
Thanks in advance.