Skip to content

Commit f45e037

Browse files
Merge pull request #1 from sergepilipchuk/sp-update-readme-24-2-1
Update Readme file
2 parents 9e07ef7 + c95b344 commit f45e037

File tree

2 files changed

+68
-26
lines changed

2 files changed

+68
-26
lines changed

Images/restore-version.jpg

50.8 KB
Loading

Readme.md

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,93 @@
44
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
55
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
66
<!-- default badges end -->
7-
# WPF Dock Layout Manager - Upgrade the app layout to a newer version
87

9-
You may have an application and [save/restore](https://docs.devexpress.com/WPF/7391/common-concepts/saving-and-restoring-layouts) its layout. If you change layout settings(show a panel, add another column, rearrange groups, and other), you can override these changes when you restore the layout.
8+
# WPF Dock Layout Manager – Upgrade the Application Layout Between Versions
109

11-
Use the `DXSerializer.LayoutUpgrade` event and the `DXSerializer.LayoutVersion` property to maintain changes.
10+
When you change the application layout (for example, adding new panels, enabling MDI mode, or rearranging groups) previously saved layouts may become outdated or incompatible. This example saves and restores layouts while supporting structural changes across different versions of the application.
1211

13-
```xml
14-
<dxdo:DockLayoutManager
15-
...
16-
dx:DXSerializer.LayoutUpgrade="OnDockLayoutManagerLayoutUpgrade"
17-
dx:DXSerializer.LayoutVersion="2.0"
18-
... />
12+
Use this example to:
13+
* Detect the version of the layout being restored.
14+
* Apply upgrade logic to adjust the layout for both [`DockLayoutManager`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Docking.DockLayoutManager) and nested controls like [`GridControl`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Grid.GridCell.GridControl).
15+
* Preserve backward compatibility while keeping layouts aligned with the current application structure.
16+
17+
![Upgrade the Application Layout Between Versions](./Images/restore-version.jpg)
18+
19+
## Implementation Details
20+
21+
### Version Management
22+
23+
The [`DXSerializer.LayoutVersion`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Core.Serialization.DXSerializer.LayoutVersion) property specifies the version of the current layout. In this example, the [`ComboBoxEdit`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Editors.ComboBoxEdit) control allows the user to change the current layout version:
24+
25+
```xaml
26+
<dxe:ComboBoxEdit EditValue="{Binding ElementName=dockLayoutManager, Path=(dx:DXSerializer.LayoutVersion)}">
27+
<sys:String>1.0</sys:String>
28+
<sys:String>2.0</sys:String>
29+
</dxe:ComboBoxEdit>
1930
```
2031

21-
```cs
32+
### Save and Restore Layouts
33+
34+
Use the [`WorkspaceManager`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Core.WorkspaceManager) component to save the application layout to an XML file and restore it when needed:
35+
36+
```csharp
37+
manager.CaptureWorkspace("TestWorkspace");
38+
manager.SaveWorkspace("TestWorkspace", layoutPath);
39+
manager.LoadWorkspace("TestWorkspace", layoutPath);
40+
manager.ApplyWorkspace("TestWorkspace");
41+
```
42+
43+
### Upgrade Logic
44+
45+
When a layout from an older version is restored, the [`GridControl`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Grid.GridCell.GridControl) and `DockLayoutManager` raise the [`DXSerializer.LayoutUpgrade`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Core.Serialization.DXSerializer.LayoutUpgrade) event to apply custom upgrade logic and adapt the layout to the current version of the application.
46+
47+
* For the [`DockLayoutManager`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Docking.DockLayoutManager), the handler switches the MDI style if the layout version is `"1.0"`:
48+
49+
```csharp
2250
void OnDockLayoutManagerLayoutUpgrade(object sender, LayoutUpgradeEventArgs e) {
2351
if (e.RestoredVersion == "1.0") {
24-
//...
52+
documentGroup1.MDIStyle = MDIStyle.MDI;
2553
}
2654
}
2755
```
28-
```vb
29-
Private Sub OnDockLayoutManagerLayoutUpgrade(ByVal sender As Object, ByVal e As LayoutUpgradeEventArgs)
30-
If e.RestoredVersion = "1.0" Then
31-
'...
32-
End If
33-
End Sub
56+
57+
* For the [`GridControl`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Grid.GridCell.GridControl), the handler applies grouping based on the restored version:
58+
59+
```csharp
60+
void OnGridControlLayoutUpgrade(object sender, LayoutUpgradeEventArgs e) {
61+
if (e.RestoredVersion == "1.0") {
62+
((GridControl)sender).GroupBy("Group");
63+
}
64+
}
3465
```
3566

36-
The `LayoutUpgrade` event is raised if the restored layout version is different from the current `LayoutVersion` value. You can increase `LayoutVersion` in a new version of your application and do the required changes in the `LayoutUpgrade` event handler.
67+
This logic ensures that older layouts can be upgraded to match the latest application structure and behavior.
3768

38-
<!-- default file list -->
39-
## Files to Look At
69+
## Files to Review
4070

4171
* [MainWindow.xaml](./CS/MainWindow.xaml) (VB: [MainWindow.xaml](./VB/MainWindow.xaml))
4272
* [MainWindow.xaml.cs](./CS/MainWindow.xaml.cs) (VB: [MainWindow.xaml.vb](./VB/MainWindow.xaml.vb))
43-
<!-- default file list end -->
4473

4574
## Documentation
4675

47-
- [Save/Restore Control Layout](https://docs.devexpress.com/WPF/7391/common-concepts/saving-and-restoring-layouts)
76+
* [DockLayoutManager](https://docs.devexpress.com/WPF/DevExpress.Xpf.Docking.DockLayoutManager)
77+
* [Layout Management](https://docs.devexpress.com/WPF/115547/controls-and-libraries/layout-management)
78+
* [DXSerializer.LayoutVersion](https://docs.devexpress.com/WPF/DevExpress.Xpf.Core.Serialization.DXSerializer.LayoutVersion)
79+
* [DXSerializer.LayoutUpgradeEvent](https://docs.devexpress.com/WPF/DevExpress.Xpf.Core.Serialization.DXSerializer.LayoutUpgradeEvent)
80+
* [Save/Restore Control Layout](https://docs.devexpress.com/WPF/7391/common-concepts/saving-and-restoring-layouts)
81+
82+
## More Examples
83+
84+
* [WPF Dock Layout Manager – Move a Layout Item in Code](https://github.com/DevExpress-Examples/wpf-docklayoutmanager-move-a-layout-item-in-code)
85+
* [WPF Dock Layout Manager – Serialize Custom Panels and Their Properties](https://github.com/DevExpress-Examples/wpf-dock-layout-manager-serialize-custom-panels-and-their-properties)
86+
* [WPF Dock Layout Manager – Serialize DockLayoutManager When You Use the TabbedDocumentUIService](https://github.com/DevExpress-Examples/wpf-docklayoutmanager-serialize-docklayoutmanager-when-tabbeddocumentuiservice-is-used)
87+
* [WPF Dock Layout Manager – Populate a LayoutGroup with ViewModel Collection](https://github.com/DevExpress-Examples/wpf-docklayoutmanager-display-viewmodels-collection-in-layoutgroup)
88+
* [WPF Dock Layout Manager – Bind the View Model Collection with LayoutAdapters](https://github.com/DevExpress-Examples/wpf-docklayoutmanager-bind-view-model-collection-with-layoutadapters)
89+
4890
<!-- feedback -->
49-
## Does this example address your development requirements/objectives?
50-
51-
[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=wpf-dock-layout-manager-upgrade-layouts-between-versions&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=wpf-dock-layout-manager-upgrade-layouts-between-versions&~~~was_helpful=no)
52-
91+
## Does this example address your development requirements/objectives?
92+
93+
[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=wpf-dock-layout-manager-upgrade-layouts-between-versions&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=wpf-dock-layout-manager-upgrade-layouts-between-versions&~~~was_helpful=no)
94+
5395
(you will be redirected to DevExpress.com to submit your response)
5496
<!-- feedback end -->

0 commit comments

Comments
 (0)