Unable to LoadFromFile when DockSite is contained within a UserControl

Docking/MDI for WPF Forum

Posted 5 years ago by Michael Janulaitis - Corner Bowl Software
Version: 18.1.0675
Avatar

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]

Comments (5)

Posted 5 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

The first thing I'd try is to move the LoadDockState call to the first time the UserControl.Loaded event handler fires, instead of in the constructor.  Let's see if that helps.  If not, then it could be something else.


Actipro Software Support

Posted 5 years ago by Michael Janulaitis - Corner Bowl Software
Avatar

That was the first thing I tried.  That makes no difference.

Posted 5 years ago by Michael Janulaitis - Corner Bowl Software
Avatar

Also I have verified the view models are attached to the DockSite prior to loading the state.  I have tried loading the state with and without the view model applied to the control.

Posted 5 years ago by Michael Janulaitis - Corner Bowl Software
Avatar

Here is what the xml file looks like.  When I step through the code when the file is loaded I see the isopen in my MessageWindowViewModel is set to false.

<DockSiteLayout xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SerializationFormat="ToolWindowsOnly" Version="2">
	<AutoHideHost />
	<Content xsi:type="SplitContainer" Orientation="Vertical" DockedSize="198,347.5">
		<UIElement xsi:type="ToolWindowContainer" DockedSize="198,341.5" SelectedWindowUniqueId="13b12bab-8758-49f1-9608-ca6e74aaeffb">
			<UIElement xsi:type="ToolWindowRef" UniqueId="13b12bab-8758-49f1-9608-ca6e74aaeffb" />
		</UIElement>
		<UIElement xsi:type="ToolWindowContainer" DockedSize="0,0" />
		<UIElement xsi:type="Workspace" />
	</Content>
	<RaftingHosts>
		<RaftingHost UniqueId="a036903b-b036-462c-9bf7-241f4a955d56" Location="2682,976" Size="200,683" WindowState="Normal">
			<AutoHideHost />
			<Content xsi:type="ToolWindowContainer" DockedSize="0,0">
				<UIElement xsi:type="Track" ContainerDockedSize="198,341.5" UniqueId="13b12bab-8758-49f1-9608-ca6e74aaeffb" />
			</Content>
		</RaftingHost>
	</RaftingHosts>
	<ToolWindows>
		<ToolWindow UniqueId="13b12bab-8758-49f1-9608-ca6e74aaeffb" SerializationId="MessageWindowViewModel" ContainerDockedSize="198,341.5" IsOpen="true" LastActiveDateTime="2019-04-02T13:45:10.0476243-06:00" State="Docked" />
	</ToolWindows>
</DockSiteLayout>

[Modified 5 years ago]

Posted 5 years ago by Michael Janulaitis - Corner Bowl Software
Avatar

Ah it's working now.  I'm not sure what I did.  Between making sure my view models were set and loading the file in the loaded event it is working.  Sorry for the cockpit error.

The latest build of this product (v24.1.2) was released 10 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.