|
4 | 4 | [](https://docs.devexpress.com/GeneralInformation/403183) |
5 | 5 | [](#does-this-example-address-your-development-requirementsobjectives) |
6 | 6 | <!-- default badges end --> |
7 | | -# WPF Dock Layout Manager - Upgrade the app layout to a newer version |
8 | 7 |
|
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 |
10 | 9 |
|
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. |
12 | 11 |
|
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 | + |
| 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> |
19 | 30 | ``` |
20 | 31 |
|
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 |
22 | 50 | void OnDockLayoutManagerLayoutUpgrade(object sender, LayoutUpgradeEventArgs e) { |
23 | 51 | if (e.RestoredVersion == "1.0") { |
24 | | - //... |
| 52 | + documentGroup1.MDIStyle = MDIStyle.MDI; |
25 | 53 | } |
26 | 54 | } |
27 | 55 | ``` |
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 | +} |
34 | 65 | ``` |
35 | 66 |
|
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. |
37 | 68 |
|
38 | | -<!-- default file list --> |
39 | | -## Files to Look At |
| 69 | +## Files to Review |
40 | 70 |
|
41 | 71 | * [MainWindow.xaml](./CS/MainWindow.xaml) (VB: [MainWindow.xaml](./VB/MainWindow.xaml)) |
42 | 72 | * [MainWindow.xaml.cs](./CS/MainWindow.xaml.cs) (VB: [MainWindow.xaml.vb](./VB/MainWindow.xaml.vb)) |
43 | | -<!-- default file list end --> |
44 | 73 |
|
45 | 74 | ## Documentation |
46 | 75 |
|
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 | + |
48 | 90 | <!-- 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 | + |
53 | 95 | (you will be redirected to DevExpress.com to submit your response) |
54 | 96 | <!-- feedback end --> |
0 commit comments