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

Issue with DataTemplate and Persistence Framework

1 Answer 157 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 12 May 2015, 01:51 PM

Hello, I am wondering if there is a known issue with items within a DataTemplate not persisting in Persistence Framework? I have a WPF application that has many RadGridViews. I use PersistenceManager to load and save grid settings from isolated storage. Persisting column orders and column sizes work perfectly on all of my grids. However there is one grid that uses a DataTemplate to contain a button for one column. Whenever the settings for this grid are saved and then reloaded the buttons disappear. Everything else on the grid persists, but the button is gone. I tried it on a simple test project to make sure that it wasn't some sort of binding issue and the problem remains. Here is the Test grid I try to persist.

<telerik:RadGridView x:Name="grdTest1"
                                            Margin="0,5,0,0" IsFilteringAllowed="True" Background="Blue"
                                            AlternateRowBackground="DarkGray" AlternationCount="2"
                                            IsReadOnly="True" AutoGenerateColumns="False"
                                            Visibility="Visible" MaxHeight="250">
            <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn>
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <Button Content="Test" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Header="First Name" DataMemberBinding="{Binding FirstName}"/>
                <telerik:GridViewDataColumn Header="Last Name" DataMemberBinding="{Binding LastName}"/>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

When loaded the first time the button is there. If I close and reopen (Save and Load) the button disappears. If I manually delete the persistence manager file from isolated storage and reload the button is there. The rest of the settings will persist which is great, but the button does not. Please let me know if there is a way to use persistence framework on a grid in this scenario.

Thanks,

Michael.

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 13 May 2015, 12:03 PM
Hi Michael,

The persistence framework does not persists DataTemplates and other properties that contains complex objects. You can find the persisted types in the Getting Started help article.

To resolve this you can define the DataTemplate in the application's resources and when you load the gridview, set the template manually. Here is an example:
<Window.Resources>
    <DataTemplate x:Key="cellTemp">
        <Button Content="Test" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
    </DataTemplate>
</Window.Resources>

IsolatedStorageProvider provider = new IsolatedStorageProvider();
provider.LoadFromStorage();
this.grdTest1.Columns[0].CellTemplate = this.Resources["cellTemp"] as DataTemplate;

You can also take a look at Custom Property Provider help article and the GridView Serialization example.

Please let me know if you need any further assistance.

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
PersistenceFramework
Asked by
Michael
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or