This question is locked. New answers and comments are not allowed.
Hello,
in our project we have defined a GridView with a custom Header:
We also have defined AutoGenerateColumns=false.
Now we wanted to use the RadGridViewSettings, but every time in the RadGridViewApplicationSettings.Save() Method we got an error:"UIElement could not be serialized".
The Problem is, that we have defined a custom Header with an UIElement in there and in the GridViewSettings the Header is also stored and when the DataCotnractSerializer want to serialize, we get an Exception.
We decided to change the customHeader to a normal Header and then the RadGridViewSettings where saved. *Fine*
But our second problem is, that we have custom columns and when the RadGridViewSettings tries to restore the grid, it clears the ColumnCollection and all the custom column Properties like custom Data Templates were loosed.
So I have modified the LoadState() method as you see beneath:
In our case this worked fine, because all we want is to restore the width of the columns for all our customColumns.
@Telerik: Maybe you have a better solution and include it in the next Release!
Thanks
Dom
in our project we have defined a GridView with a custom Header:
| <tg:GridViewDataColumn DataMemberBinding="{Binding Property}" |
| SortMemberPath="Property" |
| Width="120"> |
| <tg:GridViewDataColumn.Header> |
| <Grid> |
| <TextBlock Text="HeaderText" TextWrapping="Wrap" /> |
| </Grid> |
| </tg:GridViewDataColumn.Header> |
| </tg:GridViewDataColumn> |
We also have defined AutoGenerateColumns=false.
Now we wanted to use the RadGridViewSettings, but every time in the RadGridViewApplicationSettings.Save() Method we got an error:"UIElement could not be serialized".
The Problem is, that we have defined a custom Header with an UIElement in there and in the GridViewSettings the Header is also stored and when the DataCotnractSerializer want to serialize, we get an Exception.
We decided to change the customHeader to a normal Header and then the RadGridViewSettings where saved. *Fine*
But our second problem is, that we have custom columns and when the RadGridViewSettings tries to restore the grid, it clears the ColumnCollection and all the custom column Properties like custom Data Templates were loosed.
So I have modified the LoadState() method as you see beneath:
| if (Settings.ColumnSettings.Count > 0) |
| { |
| if (grid.AutoGenerateColumns) //Wenn das Grid auf AutoGenerate Columns eingestellt ist |
| { |
| grid.AutoGenerateColumns = false; |
| grid.Columns.Clear(); |
| foreach (ColumnSetting setting in Settings.ColumnSettings) |
| { |
| GridViewDataColumn column = new GridViewDataColumn(); |
| column.UniqueName = setting.UniqueName; |
| column.DataMemberBinding = new Binding(setting.PropertyName); |
| column.Header = setting.Header; |
| if (setting.Width != null) |
| { |
| column.Width = new GridViewLength(setting.Width.Value); |
| } |
| grid.Columns.Add(column); |
| } |
| } |
| else //Wenn die Columns selbst gemacht sind, nur die Weite verändern |
| { |
| foreach (ColumnSetting setting in Settings.ColumnSettings) |
| { |
| foreach (GridViewColumn item in grid.Columns) |
| { |
| if (item is GridViewDataColumn) |
| { |
| GridViewDataColumn col = item as GridViewDataColumn; |
| if (col != null && col.Header.ToString() == setting.Header.ToString() && col.DataMemberBinding.Path.Path == setting.PropertyName) |
| { |
| if (setting.Width != null) |
| { |
| col.Width = new GridViewLength(setting.Width.Value); |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
@Telerik: Maybe you have a better solution and include it in the next Release!
Thanks
Dom