I have an MDI application that successfully saves and loads the docksite state for the main window, however; I have an embedded docksite within a usercontrol. I subsrcibe to the IsOpen view model property which is triggered when document that contains the embedded docksite is closed via the document close button. I am able to save the embedded docksite and verify the values are updated. My view model sets the SerializationId to the name of the class. When I load the saved state, the state is ignored and no exception if fired.
<Grid>
<docking:DockSite
x:Name="dockSite"
Margin="0"
Padding="0"
ToolWindowsHaveTabImages="True"
ToolItemContainerStyle="{StaticResource ToolWindowStyle}"
ToolItemTemplateSelector="{StaticResource ToolItemTemplateSelector}"
ToolItemsSource="{Binding ToolViewModels}"
>
<docking:SplitContainer Orientation="Vertical">
<docking:Workspace>
<DataGrid>
</DataGrid>
</docking:Workspace>
</docking:SplitContainer>
</docking:DockSite>
</Grid>
public MyView()
{
InitializeComponent();
LoadDockState();
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
VM.PropertyChanged += VM_PropertyChanged;
}
private void VM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
try
{
if (e.PropertyName == nameof(DocumentItemViewModel.IsOpen))
{
if (!VM.IsOpen)
{
SaveDockState();
}
}
}
catch (Exception)
{
}
}
private static string DockFilePath
{
get
{
return string.Format(@"{0}\{1}", MyPath.UserApplicationDataPath, DOCK_FILENAME);
}
}
private void LoadDockState()
{
try
{
if (File.Exists(DockFilePath))
{
new DockSiteLayoutSerializer().LoadFromFile(DockFilePath, dockSite);
}
else
{
string layout = Properties.Resources.ViewDockManager;
new DockSiteLayoutSerializer().LoadFromString(layout, dockSite);
}
}
catch (Exception ex)
{
Commands.DisplayException.Execute(ex);
}
}
private void SaveDockState()
{
new DockSiteLayoutSerializer().SaveToFile(DockFilePath, dockSite);
}
[Modified 5 years ago]