Question

i am just getting started with AvalonDock and i have been beating my head on the wall for a few days now. I am trying to do the mundane task of loading my layout from the de-serialized dockingmanager. I have attempted what ("AvalonDock DockingManager does not load layout") this post has suggested and am still getting a empty screen.

my wpf application xaml is below:

<Window x:Name="frm_Main" x:Class="DataCAD.Forms.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:aD="http://schemas.xceed.com/wpf/xaml/avalondock"
    Title="MainWindow" Height="563.9" Width="832" WindowState="Maximized">
<Grid Margin="0,0,0,0">
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition Width="0*"/>
    </Grid.ColumnDefinitions>
    <Menu HorizontalAlignment="Left" Height="24" VerticalAlignment="Top" Width="{Binding ElementName=frm_Main,Path=ActualWidth}">
        <MenuItem Name="MnuI_File" Height="21" Width="35" HeaderStringFormat="" Header="File" >
            <MenuItem Name="mnuFile_Importcui" Padding="15,3,3,3" Header="Import Cuix" Click="MnuFile_Importcui_OnClick">
                <MenuItem.Icon>
                    <Image Width="24" Height="24" Source="/Images/cuiImport.png"/>
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Name="mnuFile_Exportcui" Padding="15,3,3,3" Header="Export Cuix" Click="MnuFile_Exportcui_OnClick">
                <MenuItem.Icon>
                    <Image Width="24" Height="24" Source="/Images/cuiExport.png"/>
                </MenuItem.Icon>
            </MenuItem>
            <Separator />
            <MenuItem Name="mnuFile_Exit" Padding="15,3,3,3" Header="Exit" Click="MnuFile_Exit_OnClick"/>
        </MenuItem>
        <MenuItem Name="MnuI_Edit" Height="21" Width="35" HeaderStringFormat="" Header="Edit" ></MenuItem>
        <MenuItem Name="MnuI_View" Height="21" Width="42" HeaderStringFormat="" Header="View" >
            <MenuItem Name="mnuView_Cuixexplorer" IsChecked="True" IsCheckable="True" Padding="15,3,3,3" Header="Cuix Explorer" Click="MnuView_Cuixexplorer_OnClick"/>
        </MenuItem>
    </Menu>
    <aD:DockingManager x:Name="Dockman" Margin="0,21,1,0">
        <aD:DockingManager.Theme>
            <aD:AeroTheme/>
        </aD:DockingManager.Theme>
        <aD:LayoutRoot>
            <aD:LayoutPanel Orientation="Vertical">
                <aD:LayoutPanel Orientation="Horizontal">
                    <aD:LayoutAnchorablePaneGroup DockWidth="150" Orientation="Vertical">
                        <aD:LayoutAnchorablePane x:Name="CuixExplorerAnchor" DockWidth="150">
                            <aD:LayoutAnchorable x:Name="CuixExplorer" ContentId="CuixExplorer" Title="Cuix Explorer">
                                <TreeView Name="trv_CuixDisplay" AllowDrop="True"  Drop="trv_CuiDisplay_onDrop">
                                </TreeView>
                            </aD:LayoutAnchorable>
                        </aD:LayoutAnchorablePane>
                        <aD:LayoutAnchorablePane x:Name="Gen_PropertiesAnchor" DockWidth="150">
                            <aD:LayoutAnchorable x:Name="Gen_Properties" ContentId="Properties" Title="Properties">
                                <Grid x:Name="grid"></Grid>
                            </aD:LayoutAnchorable>
                        </aD:LayoutAnchorablePane>
                    </aD:LayoutAnchorablePaneGroup>
                    <aD:LayoutDocumentPaneGroup Orientation="Vertical" DockWidth="*" x:Name="DocPane">
                        <aD:LayoutDocumentPane x:Name="DockingMainWindow">
                            <aD:LayoutDocument ContentId="default" Title="default">
                                <RichTextBox x:Name="DefaultTextBox"></RichTextBox>
                            </aD:LayoutDocument>
                        </aD:LayoutDocumentPane>
                    </aD:LayoutDocumentPaneGroup>
                </aD:LayoutPanel>
                <aD:LayoutAnchorablePaneGroup Orientation="Vertical" DockHeight="150" >
                    <aD:LayoutAnchorablePane DockHeight="150" >
                        <aD:LayoutAnchorable ContentId="output" Title="Output">
                            <TextBox x:Name="OutpuTextBox"></TextBox>
                        </aD:LayoutAnchorable>
                    </aD:LayoutAnchorablePane>
                </aD:LayoutAnchorablePaneGroup>
            </aD:LayoutPanel>
        </aD:LayoutRoot>
    </aD:DockingManager>
</Grid>

My setting xml is below:

<?xml version="1.0" encoding="utf-8"?>
  <LayoutRoot xmlns:xsd="http://www.w3.org/2001/XMLSchema"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <RootPanel Orientation="Vertical">
    <LayoutPanel Orientation="Horizontal">
      <LayoutAnchorablePaneGroup Orientation="Vertical" DockWidth="150">
        <LayoutAnchorablePane DockWidth="150">
          <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Cuix Explorer" IsSelected="True" ContentId="CuixExplorer" />
        </LayoutAnchorablePane>
        <LayoutAnchorablePane DockWidth="150">
          <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Properties" IsSelected="True" ContentId="Properties" />
        </LayoutAnchorablePane>
      </LayoutAnchorablePaneGroup>
      <LayoutDocumentPaneGroup Orientation="Vertical">
        <LayoutDocumentPane>
          <LayoutDocument Title="default" IsSelected="True" IsLastFocusedDocument="True" ContentId="default" LastActivationTimeStamp="10/05/2013 00:30:01" />
        </LayoutDocumentPane>
      </LayoutDocumentPaneGroup>
    </LayoutPanel>
    <LayoutAnchorablePaneGroup Orientation="Vertical" DockHeight="150">
      <LayoutAnchorablePane DockHeight="150">
        <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Output" IsSelected="True" ContentId="output" />
      </LayoutAnchorablePane>
    </LayoutAnchorablePaneGroup>
  </RootPanel>
  <TopSide />
  <RightSide />
  <LeftSide />
  <BottomSide />
  <FloatingWindows />
  <Hidden />
</LayoutRoot>

my code is below:

public MainWindow()
{
    InitializeComponent();
    LoadLayout();
    Left = Settings.Default.MAINWINDOW_LEFT;
    Top = Settings.Default.MAINWINDOW_TOP;
    Width = Settings.Default.MAINWINDOW_WIDTH;
    Height = Settings.Default.MAINWINDOW_HEIGHT;
    WindowState = (Settings.Default.MAINWINDOW_ISMAXIMIZED) ? WindowState.Maximized : WindowState.Normal;
}


 private void MainWindow_OnClosing(object sender , CancelEventArgs cancelEventArgs)
{

    Settings.Default.MAINWINDOW_LEFT = Left;
    Settings.Default.MAINWINDOW_TOP = Top;
    Settings.Default.MAINWINDOW_WIDTH = Width;
    Settings.Default.MAINWINDOW_HEIGHT = Height;
    Settings.Default.MAINWINDOW_ISMAXIMIZED = (WindowState == WindowState.Maximized);
    Settings.Default.CUIXEXPLORER_ISVISIBLE = CuixExplorer.IsVisible;
    Settings.Default.CUIXEXPLORER_DOCKLOCATION = CuixExplorer.PreviousContainerIndex;
    Settings.Default.CUIXEXPLORER_WIDTH = CuixExplorer.FloatingWidth;
    Settings.Default.CUIXEXPLORER_HEIGHT = CuixExplorer.FloatingHeight;
    Settings.Default.Save();
    SaveLayout();
}

private void SaveLayout()
{
    var serializer = new XmlLayoutSerializer(Dockman);

    using (var stream = new StreamWriter(_settingsFile))
    {
        serializer.Serialize(stream);
    }
}

private void LoadLayout()
{
    var serializer = new XmlLayoutSerializer(Dockman);
    using (var stream = new StreamReader(_settingsFile))
    {
        serializer.Deserialize(stream);
    }
}

any help is greatly appreciated. Thanks in advance.

Was it helpful?

Solution 2

I have come across this issue and the problem is not the callback. It is unnecessary. The method to Deserialize will NOT work before Window_Loaded event happen. If you call it before like in this case in the window constructor the object is not fully loaded therefore cannot load properly the xml. Doing so will cause the white screen issue.

I came upon this error while switching from Syncfusion Docking Manager to Exceed Avalon Dock. I was changing the code for the loading and saving only and not where they are called from. Syncfusion dock manager loading DOES work when called f the constructor and this one obviously is not working there. No big deal, Window_Loaded do the job.

OTHER TIPS

The reason i was not able to Deserialize my layout was because i was missing the Serializer.LayoutSerializationCallback event in my LoadLayout method.

new LoadLayout method:

public void LoadLayout()
{
    var serializer = new XmlLayoutSerializer(DockingManagerMain);

    // Imparitive for Deserialization
    serializer.LayoutSerializationCallback += (s, args) =>
    {
        args.Content = args.Content;
    };

    serializer.Deserialize(DockingLayoutConfig);
}

Solution from Franck works with the UserControl_Loaded event in codebehind. a nicer thing is inherit your viewmodel from Screen and override the OnViewLoaded(object view) method. in your xaml from your view give your dockmanager a x:Name so that you can use it in the OnViewLoaded method.

Something like this (combination of Franck with Trae Moore's code):

protected override void OnViewLoaded(object view) 
{
   base.OnViewLoaded(view);
   MyView v = view as MyView;
   if (v?.myDockManager != null) {
       var ser = new XmlLayoutSerializer(v.myDockManager);
       // ...
   }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top