Version

Persisting Specific Control Properties

The following code demonstrates how you can selectively choose to persist only the Background property of the TextBox control.

In XAML:

<TextBox x:Name="txtAccount" Background="#FFCCFAEA">
    <ig:PersistenceManager.Settings>
        <ig:PersistenceSettings SavePersistenceOptions="OnlySpecified" >
            <ig:PersistenceSettings.PropertySettings>
                <ig:PropertyNamePersistenceInfo PropertyName="Background" Options="PropertyPath" />
            </ig:PersistenceSettings.PropertySettings>
        </ig:PersistenceSettings>
    </ig:PersistenceManager.Settings>
</TextBox>

Set the PersistenceSettings object’s SavePersistenceOptions property to OnlySpecified.

Use the PropertyNamePersistenceInfo object’s PropertyName property to specify that you will persist the Background property of the TextBox.

The same functionality can be implemented in the code-behind.

In Visual Basic:

' create a new PersistenceSettings object
Dim settings As New PersistenceSettings()
' set save persistence option - OnlySpecified
settings.SavePersistenceOptions = Infragistics.Persistence.Primitives.PersistenceOption.OnlySpecified
' we will identify the specific property by its name
Dim pnpi As New PropertyNamePersistenceInfo()
pnpi.PropertyName = "Background"
' add the property in the PropertySettings collection
settings.PropertySettings.Add(pnpi)
Dim memoryStream As MemoryStream = PersistenceManager.Save(txtAccount, settings)

In C#:

// create a new PersistenceSettings object
PersistenceSettings settings = new PersistenceSettings();
// set save persistence option - OnlySpecified
settings.SavePersistenceOptions = Infragistics.Persistence.Primitives.PersistenceOption.OnlySpecified;
// we will identify the specific property by its name
PropertyNamePersistenceInfo pnpi = new PropertyNamePersistenceInfo();
pnpi.PropertyName = "Background";
// add the property in the PropertySettings collection
settings.PropertySettings.Add(pnpi);
MemoryStream memoryStream = PersistenceManager.Save(txtAccount, settings);

Related Topics