This is a migrated thread and some comments may be shown as answers.

IsolatedStorageProvider kills AutogenerateColums setting

12 Answers 216 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
Sven
Top achievements
Rank 1
Sven asked on 16 Jul 2012, 02:45 PM
Hello there!
We are using Telerik WPF controls and the IsolatedStorageprovider to persist UI Settings. Now we've got the problem that the Columns of the RADGridViews are destroyed and AutoGenerateColumns is set from false to true when the LoadFromStorage Method is executed. :-(
Interesting is that the Grids don't even have a StorageId...
Is there a way to avoid this unfortunate behavior?
I should also mention that the grids are arranged in a user Control.

brgds
Sven Weiberg
Format Software Service

12 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 19 Jul 2012, 06:51 AM
Hi Sven,

 You can find attached a sample project that we can us in our future investigation of this issue. It shows a successful save/load of RadGridView with IsolatedStorage Provider. It's actually mandatory to set a Storage ID on the RadGridView, otherwise no save operation will be performed. The steps you can check out are;
1) Run the application
2) Drag Id Column To the Right
        3) Save
        4)Drag the Id Column to the Left
        4) Load
        5) The Id Column is again on the right . This indicates successful persistence.
Please also note that the AutogenerateColumns is set to True and it is not reset to False after Load ( see the MessageBox Text that appears). Furthermore, you can check out the same behavior if you use save to and load from stream ( comment the IsolatedStorage logic and uncomment the stream logic lines).
Is it possible for you try to modify this project so that the issue you have encountered is reproducible ? This way we would be better able to advice you. 

All the best,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Sven
Top achievements
Rank 1
answered on 24 Jul 2012, 08:43 AM
Ok, I succeeded to reproduve the issue. My problem is not that s.th. is not persisted that I want to be persisted. My problem is that s.th. is persisted that should not be persisted!

You have to do the following steps:
- Remove the PersistenceManager.StorageId from GridView
- Remove this Customproperty stuff. The constructor should look like this

public MainWindow()
{
    InitializeComponent();
 
    //this.xGridView.SetValue(GridViewHelper.IsExpandWatcherActiveProperty, true);
    // register the custom property provider for the RadGridView:
    //ServiceProvider.RegisterPersistenceProvider<ICustomPropertyProvider>(typeof(RadGridView), new GridViewCustomPropertyProvider());
    this.xGridView.ItemsSource = DivisionsService.GetDivisions();
    this.EnsureLoadState();
}

- Provide the Window with a PersistenceManager.StorageId
- Implement Loaded and Closed events of the window

private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            IsolatedStorageProvider isoProvider = new IsolatedStorageProvider();
            isoProvider.LoadFromStorage();
        }
 
        private void Window_Closed(object sender, EventArgs e)
        {
            IsolatedStorageProvider isoProvider = new IsolatedStorageProvider();
            isoProvider.SaveToStorage();
        }

- Important: Run the application once.
- After you ran the application, add some data columns to the grid and change the AutoGenerateColumns settings.
<telerik:RadGridView x:Name="xGridView" Grid.Row="1"
        AutoGenerateColumns="False"
                     SelectionMode="Extended">
    <telerik:RadGridView.Columns>
    <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Path=Name}" />
    <telerik:GridViewDataColumn Header="Id" DataMemberBinding="{Binding Path=Id}" />
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

- Run the application again. You will find your work from the last step to be completely ignored.

If you step a bit into the problem you will find out, that the call to IsoProvider.LoadFromStorage() changes the AutoGenerateColumns setting of the grid.

The only way out of this is to comment out the LoadFromStorage() method in Window_Loaded and run the application.
Is this behaviour by Design?

brgds
Sven Weiberg

0
Alex Fidanov
Telerik team
answered on 27 Jul 2012, 07:17 AM
Hi Sven,

 You should not be removing the custom property provider for the GridView. If you set a persistence storage id to the window, this means that it will save its content recursively, including the gridview as its descendant. The GridView should not be serialized without a provider and is not expected to work without one. Is there any reason why you are removing the grid's provider?

Regards,
Alex Fidanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Sven
Top achievements
Rank 1
answered on 27 Jul 2012, 08:34 AM
Ok, if I add a StorageID to the grid, changes are not completely ignored. But what to do if I want the window position and size to be persisted but not the grid stuff?
And what if I want to choose what is persisted and what not? Is this possible?

brgds
Sven Weiberg
0
Tina Stancheva
Telerik team
answered on 01 Aug 2012, 07:52 AM
Hi Sven,

You can take advantage of the PersistenceManager.SerializationOptions property. It allows you to control which properties of a persisted UIElement should be saved. For example you can use them to exclude the Window.Content property from the list of persisted properties thus not saving anything that is defined within the content of the window while saving all other Window properties. 

Please have a look at our documentation that provides further information about the PersistenceManager 
serialization options. Give them a try and let us know if we can assist you with anything else.
 

Regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Sven
Top achievements
Rank 1
answered on 07 Aug 2012, 12:24 PM
It does not work. Looks like the PersistenceManager destroys the Binding Converter. I will give you some furhter information as soon as I find some time for that. And this

<telerik:PersistenceManager.SerializationOptions>
    <telerik:SerializationMetadataCollection Operator="Or">
        <telerik:PropertyNameMetadata Condition="Except" Expression="Window.Content" SearchType="PropertyName" />
        <telerik:PropertyNameMetadata Condition="Except" Expression="Grid" SearchType="PropertyName" />
    </telerik:SerializationMetadataCollection>
</telerik:PersistenceManager.SerializationOptions>

is completely ignored. Is still persists all...

brgds
Sven
0
Tina Stancheva
Telerik team
answered on 10 Aug 2012, 12:49 PM
Hi Sven,

The PropertyNameMetadata should describe a property of the control on which the SerializationOptions are applied.

The SerializationOptions collection allows you to define which properties of the control, it is applied to, should/shouldn't be persisted. This means that in your case the PropertyNameMetadata should describe a property of the Window - so you can define it like so:
<Window ...
        Closed="Window_Closed"
        Loaded="Window_Loaded"
        telerik:PersistenceManager.StorageId="Window">
    <telerik:PersistenceManager.SerializationOptions>
        <telerik:SerializationMetadataCollection>
            <telerik:PropertyNameMetadata Condition="Except"
                              Expression="Content"
                              SearchType="PropertyName" />
        </telerik:SerializationMetadataCollection>
    </telerik:PersistenceManager.SerializationOptions>
    ...
</Window >

I modified our solution to demonstrate this approach. If you follow the steps you described earlier in this conversation, you'll see that the GridView control isn't persisted by the PersistenceFramework.

Greetings,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Sven
Top achievements
Rank 1
answered on 14 Aug 2012, 03:09 PM
Ok. The stuff with the SerializationOptions works now. Was my fault. There was another Element that had a StorageID.
But there still remains an Issue:
If I persist a grid via PersistanceManager the Binding Converter is removed. I can reproduce this with your solution. Just add a binding converter like this:
<Window.Resources>       
    <local:StatusConverter x:Key="StatusConverter" />
</Window.Resources>

<telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Path=Name}" />
                <telerik:GridViewDataColumn Header="Id" DataMemberBinding="{Binding Path=Id, Converter={StaticResource StatusConverter}}" />
            </telerik:RadGridView.Columns>

public class StatusConverter : IValueConverter
    {
 
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
 
            if (value != null)
            {
 
                int number = System.Convert.ToInt32(value);
 
                switch (number)
                {
                    case 0:
                        return "One";
                    case 1:
                        return "Two";
                    case 2:
                        return "Three";
                }
            }
 
            return string.Empty;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    }

If you then add storage ID to the GridView you will find the Converter being ignored after restart.
0
Tina Stancheva
Telerik team
answered on 17 Aug 2012, 02:51 PM
Hello Sven,

I can't reproduce the issue in my solution - I modified it to add a converter and every time I load the Window, the converter is called and the values in the ID column are converted. Can you please have a look at the solution and let me know if I'm missing something? Thank you in advance.

All the best,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Sven
Top achievements
Rank 1
answered on 20 Aug 2012, 08:40 AM
Hello Tina!
You missed to add a storageID to the Grid View

<telerik:RadGridView x:Name="xGridView"
                             Grid.Row="1" AutoGenerateColumns="False"
                             SelectionMode="Extended"
                             telerik:PersistenceManager.StorageId="xGridView">

brgds
Sven
0
Accepted
Tina Stancheva
Telerik team
answered on 21 Aug 2012, 01:27 PM
Hello Sven,

I'm sorry, I thought you didn't want to persist the RadGridView and this is why I haven't set the StorageId. Please note that when you apply the PersistenceManager.SerializationOptions to exclude the content of the Window, the RadGridView won't be persisted. But as soon as you set a StorageId in the RadGridView definition, the PersistenceFramework will try to persist it. However, as Alex earlier noted, you can't persist the RadGridView control without defining a custom property provider for it.

And when I modified my solution to set the StorageId property in the RadGridView definition and I added a GridViewCustomPropertyProvider class, the converter was properly applied. Please have a look at the solution and let me know if it works for you.

Kind regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Sven
Top achievements
Rank 1
answered on 22 Aug 2012, 10:44 AM
Ok. Now I got it.
I am not sure if I want to persist the grid. Actually not, but I like the idea of being able to do it in the near future.
I just forgot the information Alex provided. I think this thread can be closed now. Thanks for your support.

brgds
Sven
Tags
PersistenceFramework
Asked by
Sven
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Sven
Top achievements
Rank 1
Alex Fidanov
Telerik team
Tina Stancheva
Telerik team
Share this question
or