3

私は AvalonDock を使い始めたばかりで、数日間壁に頭を悩ませています。デシリアライズされたドッキングマネージャーからレイアウトをロードするというありふれたタスクを実行しようとしています。この投稿で提案されていること (「AvalonDock DockingManager がレイアウトをロードしない」) を試みましたが、まだ空の画面が表示されます。

私のwpfアプリケーションxamlは以下です:

<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>

私の設定xmlは以下の通りです:

<?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>

私のコードは以下です:

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);
    }
}

どんな助けでも大歓迎です。前もって感謝します。

4

3 に答える 3

5

レイアウトできなかったのは、メソッドでイベントDeserializeが欠落していたためです。Serializer.LayoutSerializationCallbackLoadLayout

新しい LoadLayout メソッド:

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

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

    serializer.Deserialize(DockingLayoutConfig);
}
于 2013-12-05T18:28:43.813 に答える