I have multiple XamGrids in my project using the few group columns (and its columns hierarchy under it) exactly same.
Is there a way i can create key for reuseable group column XAML and use it in different XamGrids. This way I will not have to write duplicate XAML for these Group Columns.
After looking at the code, I see why it would be difficult to fix the IsSorted problem - but I was able to come up with a suitable workaround. On the persistence problem, it turns out that it wasn't directly related to the cloning behavior. I was saving the grid settings in the page OnNavigated - and it appears maybe that the XamGrid was already starting to be Disposed by then. I moved the SaveLastSettings to OnNavigating instead and it seems to work as expected - why it worked before I'm not sure.
The ability to store column layouts in a resource dictionary and then dynamically have them do the right thing based on TargetType is really powerful and makes XAML management so much simpler when you have a lot of grids and a lot of different layouts of related objects. Unfortunately, there seems to be a problem with your provided code, in that if the layout has a column that has the IsSorted property, it throws an exception. I asked support about this, and all they would say is that it is a known problem and "don't do that". At first, I thought I could live with this because we have our own persistence mechanism that saves/loads a users prefered view of the grid, and as long as that worked, it wouldn't really matter. However, when I use your cloning behavior, the following save code also breaks:
ugv.ColumnSettings = JsonConvert.SerializeObject(from col in this.Columns.DataColumns select new { Key = col.Key, SortDirection = col.IsSorted, Visibility = col.Visibility, Width = col.ActualWidth }, Formatting.Indented);
When using your cloning behavior, columns correctly sort in the grid, but when the above code is called, col.IsSorted is always "None" even when the column is sorted. The code of course works as expected when not using the behavior. What gives with IsSorted and this behavior???
Hello Gajender,
Thank you for post. I have been looking into the question that you are having and what I can suggest is creating a custom behavior. I have create a sample application for you, that shows how you can define a collection of columns and using a behavior to clone those columns in multiple XamGrids. The behavior have Columns and ColumnLayouts properties that are from type ObservableCollection<ColumnBase> and ObservableCollection<ColumnLayout>. You can define a collection of columns in the resources and set the Columns property of the behavior to that collection, as StaticResource. The behavior will clone all columns and will add them to each XamGrid, that has the behavior set.
Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir, MCPD
Developer Support Supervisor - XAML
Infragistics
www.infragistics.com/support