I tried to save and load user settings to xamgrid using persistence framework 11.2
XAML:
<ig:XamGrid AutoGenerateColumns="False" ColumnLayoutHeaderVisibility="Never" Cursor="Hand" Height="680" Name="dgQResult" ItemsSource="{Binding Path=SchedulingQueueResult}" Margin="8,7,15,8" Width="Auto" h:HelpProvider.ScreenName="Scheduling Queue" h:HelpProvider.ControlName="dgQResult" Loaded="dgQResult_Loaded" MouseDoubleClick="dgQResult_MouseDoubleClick"> <ig:XamGrid.FilteringSettings> <ig:FilteringSettings AllowFiltering="FilterMenu" /> </ig:XamGrid.FilteringSettings> <ig:XamGrid.SelectionSettings> <ig:SelectionSettings CellClickAction="SelectRow" RowSelection="Single" /> </ig:XamGrid.SelectionSettings> <i:Interaction.Triggers> <i:EventTrigger EventName="MouseDoubleClick" > <cmd:EventToCommand PassEventArgsToCommand="True" Command="{Binding Path=ViewOrderCommand}" /> </i:EventTrigger> </i:Interaction.Triggers> <ig:ContextMenuService.Manager> <ig:ContextMenuManager OpenMode="RightClick"> <ig:ContextMenuManager.ContextMenu > <ig:XamContextMenu Name="XamSchedulingQMenu" Opening="XamSchedulingQMenu_Opening"> <ig:XamMenuItem Header="View All Enrollment Information" > <ig:XamMenuItem.InputBindings> <MouseBinding MouseAction="LeftClick" Command="{Binding Path=LoadOtherScreenCommand}" CommandParameter="PatientEnrollment" /> </ig:XamMenuItem.InputBindings> </ig:XamMenuItem>
</ig:XamContextMenu> </ig:ContextMenuManager.ContextMenu> </ig:ContextMenuManager> </ig:ContextMenuService.Manager> <ig:XamGrid.Columns> <ig:TextColumn Key="OrderIDKey" HeaderText="OrderIDKey" Visibility="Collapsed" Width="Auto" IsFilterable="True" IsFixable="True" IsGroupable="True" IsMovable="True" IsResizable="True" IsSortable="True" IsSummable="True" VerticalContentAlignment="Center" IsReadOnly="True" />
... Other Columns ...
<ig:ColumnLayout Key="Children"> <ig:ColumnLayout.Columns> <ig:TextColumn Key="OrderIDKey" HeaderText="OrderIDKey" Visibility="Collapsed" Width="Auto" IsFilterable="True" IsFixable="True" IsGroupable="True" IsMovable="True" IsResizable="True" IsSortable="True" IsSummable="True" VerticalContentAlignment="Center" IsReadOnly="True" />
.... Other Columns ...
</ig:ColumnLayout.Columns> </ig:ColumnLayout> </ig:XamGrid.Columns> </ig:XamGrid>
XAML.CS:
On window Closing event: (Saved user settings)
using (MemoryStream mStream = PersistenceManager.Save(grid, GetStandardGridPersistenceSettings())) { mStream.Position = 0; using (FileStream fs = new FileStream(@"E:\temp\persistence_scheduling.xml", FileMode.OpenOrCreate)) { mStream.WriteTo(fs); } }
On Window Loaded Event: (Load Settings):
if (!System.IO.File.Exists(@"E:\temp\persistence_scheduling.xml")) return; using (FileStream fs = File.OpenRead(@"E:\temp\persistence_scheduling.xml")) { PersistenceManager.Load(grid, fs, GetStandardGridPersistenceSettings()); }
Common Funtions:
public static PersistenceSettings GetStandardGridPersistenceSettings() { PersistenceSettings settings = new PersistenceSettings(); settings.SavePersistenceOptions = PersistenceOption.OnlySpecified; // Filter menu PropertyNamePersistenceInfo prop = new PropertyNamePersistenceInfo(); prop.PropertyName = "RowFiltersCollection"; settings.PropertySettings.Add(prop); prop = new PropertyNamePersistenceInfo(); prop.PropertyName = "Columns[].Key"; settings.PropertySettings.Add(prop); // Filter menu prop = new PropertyNamePersistenceInfo(); prop.PropertyName = "Columns[].FilterColumnSettings"; settings.PropertySettings.Add(prop); // Maybe this is for top filter row? prop = new PropertyNamePersistenceInfo(); prop.PropertyName = "FilteringSettings"; settings.PropertySettings.Add(prop); // Column sort prop = new PropertyNamePersistenceInfo(); prop.PropertyName = "SortingSettings"; settings.PropertySettings.Add(prop); // Column order? prop = new PropertyNamePersistenceInfo(); prop.PropertyName = "ColumnMovingSettings"; settings.PropertySettings.Add(prop); // Column width? prop = new PropertyNamePersistenceInfo(); prop.PropertyName = "ColumnResizingSettings"; settings.PropertySettings.Add(prop); // Visible columns? prop = new PropertyNamePersistenceInfo(); prop.PropertyName = "ColumnChooserSettings"; settings.PropertySettings.Add(prop); return settings; }
Error On Load Settings:
PersistenceGroup elements don't match elements in stream. at Infragistics.Persistence.PersistenceManager.LoadGroup(PersistenceGroup group, Stream stream, PersistenceSettings settings) at Infragistics.Persistence.PersistenceManager.Load(DependencyObject obj, Stream stream, PersistenceSettings settings) at RxVector.Views.Queues.PreOrder.SchedulingQ.DeSeralizeGridSettings(XamGrid grid, String gridSettings) in E:\TFS\RxVector\RxVector\Views\Queues\PreOrder\SchedulingQ.xaml.cs:line 201 at RxVector.Views.Queues.PreOrder.SchedulingQ.dgQResult_Loaded(Object sender, RoutedEventArgs e) in E:\TFS\RxVector\RxVector\Views\Queues\PreOrder\SchedulingQ.xaml.cs:line 391 at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e) at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent) at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root) at MS.Internal.LoadedOrUnloadedOperation.DoWork() at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks() at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
Was there a solution for this problem. I get the same when trying to persist a xamDiagram . I added the persistance code that is working in 14.1 to one of the samples i found on this site. On two machines i get this error, on the third i get no error but the diagram is not restored, the shapes all appear in the top left corner of the diagram
Hello Sana,
I am just checking the progress of this issue and was wondering if you managed to achieve your goal or if you need any further assistance on the matter.
I have changed the target framework to 4.0 and everything seems to work ok on my side. I also changed the FileMode in the SeralizeGridSettings method to Create, because a new file should be created every time you close the application. When I sort a column and filter the settings are persisted correctly. I used version 14.1. Please let me know if this helps you or you have further questions on this matter. Looking forward for your reply.
Hi,
Thank you for your research and sample solution. When i tried your solution, i didn't get any error, but i think it is not working as it is supposed to work. The main requirement here is, i want to save the user settings like column filters and column sorting and when user reloads that form, those settings should apply automatically. With your solution, i tried saving the settings with one column filter and when i reloaded the form, that filter is not applied. Can you please check on your side.
With XamGrid, is this the only way to save and load the user settings?
Also my application is configured with .Net 4.0 version not 4.5. So i changed your application to 4.0 and tested. May be .Net version 4.0 has any issues with persistence framework?
Also i just want to let you know that i am using GalaSoft MVVM framework in my application and i am binding the data with view model.
I have tried to reproduce your behavior with version 11.2, but I wasn't able to. I created a sample project for you using your approach. Could you please modify it, so the issue is reproducible there, so we could be able to investigate this further for you.
Looking forward for your reply.