# Save RadDocking Layout When the Control is Unloaded

## Environment

<table>
	<tbody>
		<tr>
			<th scope="row">Product Version</th>
			<td>2022.3 912</td>
		</tr>
		<tr>
			<th scope="row">Product</th>
			<td>RadDocking for WPF</td>
		</tr>
	</tbody>
</table>

## Description

How to save the layout of the RadDocking control when its unloaded.

## Solution

1. Add a new event handler for the `Unloaded` event of the `RadDocking` using the `EventManager.RegisterClassHandler` static method.

   **Add a new event handler for the Unloaded event of RadDocking**

   ```C#
       EventManager.RegisterClassHandler(typeof(RadDocking), RadDocking.   UnloadedEvent, new RoutedEventHandler(OnUnloaded));
   ```

   ```VB.NET
       EventManager.RegisterClassHandler(GetType(RadDocking), RadDocking.  UnloadedEvent, New RoutedEventHandler(OnUnloaded))
   ```

2. Implement the save logic in the newly added event handler for the `Unloaded` event.

   **Sample implementation of saving the layout in the newly added   handler**

   ```C#
       private void OnUnloaded(object sender, RoutedEventArgs e)
       {
           using (IsolatedStorageFile storage = IsolatedStorageFile.   GetUserStoreForAssembly())
           {
               using (var isoStream = storage.OpenFile("RadDocking_Layout.xml",    FileMode.Create))
               {
                   this.radDocking.SaveLayout(isoStream);
               }
           }
       }
   ```

   ```VB.NET
       Private Sub OnUnloaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
           Using storage As IsolatedStorageFile = IsolatedStorageFile. GetUserStoreForAssembly()
               Using isoStream = storage.OpenFile("RadDocking_Layout.xml",     FileMode.Create)
                   Me.radDocking.SaveLayout(isoStream)
               End Using
           End Using
       End Sub
   ```
