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

Persistence Framework kills binding

3 Answers 145 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
Stefan
Top achievements
Rank 1
Stefan asked on 22 Nov 2012, 01:39 AM
Hello,

I bind 2 Controls

<telerik:RadToggleButton x:Name="ShowLogButton"  Grid.Column="1" Grid.Row="1" Content="..."></telerik:RadToggleButton>
<telerik:RadListBox ItemsSource="{Binding Path=Log}" DisplayMemberPath="Description" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" Height="70" Visibility="{Binding ElementName=ShowLogButton, Path=IsChecked,  Converter={StaticResource ControlVisibilityConverter}}">
</telerik:RadListBox>

Follow Visible attribute, after saving and loading my window with Persistence Framework my toggle button is broken and dont works anymore

This code helps

<telerik:RadToggleButton x:Name="ShowLogButton"  Grid.Column="1" Grid.Row="1" Content="..."></telerik:RadToggleButton>
<telerik:RadListBox ItemsSource="{Binding Path=Log}" DisplayMemberPath="Description" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" Height="70" Visibility="{Binding ElementName=ShowLogButton, Path=IsChecked,  Converter={StaticResource ControlVisibilityConverter}}">
<telerik:PersistenceManager.SerializationOptions>
    <telerik:SerializationMetadataCollection>
        <telerik:PropertyNameMetadata Condition="Except" Expression="Visibility" SearchType="PropertyName" />
    </telerik:SerializationMetadataCollection>
</telerik:PersistenceManager.SerializationOptions>
</
telerik:RadListBox>

Should i use this for every binded Porperty? Can i exclude any binded properties from serialisation ?

3 Answers, 1 is accepted

Sort by
0
Stefan
Top achievements
Rank 1
answered on 22 Nov 2012, 12:01 PM
its the same if i have a simple textbox, binding is broke after reloading

<TextBlock Text="{Binding Name}" MaxWidth="280" TextWrapping="Wrap" Margin="5,0,0,0"  Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" />
0
Stefan
Top achievements
Rank 1
answered on 22 Nov 2012, 12:40 PM
can i except whole control from serialisation if i serialize my window ?
0
Tina Stancheva
Telerik team
answered on 26 Nov 2012, 02:31 PM
Hi Stefan,

When using the PersistenceFramework, you need to keep in mind that the framework saves the values of the UIProperties of all UIElements within the persisted control. This is why when you have a binding, the persistence manager will take the value defined by the binding and well save it as the value of the property in question. So if you have a binding for the Visibility property and the binding sets the Visibility to False, the persistence manager will save the Visibility property with value of False. This is why the approach for removing the bound properties out of the list with saved properties is a good approach.

And in case, you'd like to remove certain controls from the list pf persisted properties, you'll need to track the properties that define them. For example if you have a Window with one TextBlock in it, like so:
<Window x:Class="WpfApplication1.MainWindow"
        Title="MainWindow">
    <TextBlock Text="{Binding Name}"
               MaxWidth="280"
               TextWrapping="Wrap"
               Margin="5,0,0,0"
               Grid.Row="0"
               Grid.Column="1"
               VerticalAlignment="Top" />
</Window>
Then you can remove the TextBlock from the list of persisted controls, by removing the Window.Content property from the list of persisted Window properties.
<Window x:Class="WpfApplication1.MainWindow"
        Title="MainWindow">
        <telerik:PersistenceManager.SerializationOptions>
            <telerik:SerializationMetadataCollection>
                <telerik:PropertyNameMetadata Condition="Except"
                                     Expression="Content"
                                     SearchType="PropertyName" />
            </telerik:SerializationMetadataCollection>
        </telerik:PersistenceManager.SerializationOptions>
        <TextBlock Text="{Binding Name}"
                   MaxWidth="280"
                   TextWrapping="Wrap"
                   Margin="5,0,0,0"
                   Grid.Row="0"
                   Grid.Column="1"
                   VerticalAlignment="Top" />
</Window>

Instead,if the Window structure is such that the TextBlock is part of a Grid panel:
<Window x:Class="WpfApplication1.MainWindow"
        Title="MainWindow">
    <Grid>
        <TextBlock Text="{Binding Name}"
                   MaxWidth="280"
                   TextWrapping="Wrap"
                   Margin="5,0,0,0"
                   Grid.Row="0"
                   Grid.Column="1"
                   VerticalAlignment="Top" />
    </Grid>
</Window>
Then you need to remove the Grid.Children property from the list of persisted properties:
<Window x:Class="WpfApplication1.MainWindow"
        Title="MainWindow">
    <Grid>
        <telerik:PersistenceManager.SerializationOptions>
            <telerik:SerializationMetadataCollection>
                <telerik:PropertyNameMetadata Condition="Except"
                                 Expression="Children"
                                 SearchType="PropertyName" />
            </telerik:SerializationMetadataCollection>
        </telerik:PersistenceManager.SerializationOptions>
        <TextBlock Text="{Binding Name}"
                   MaxWidth="280"
                   TextWrapping="Wrap"
                   Margin="5,0,0,0"
                   Grid.Row="0"
                   Grid.Column="1"
                   VerticalAlignment="Top" />
    </Grid>
</Window>

Basically you can define a SerializationOptions collection for each control in your Window. You only need to have in mind that you basically persist the properties of the main control (for example the Window), but if its Content/Items/Header/Children define other controls, in order to not persist them, you have to exclude the Content/Items/Header/Children property from the parent control. 

Let me know if that information helps.

Kind regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
PersistenceFramework
Asked by
Stefan
Top achievements
Rank 1
Answers by
Stefan
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or