gpt4 book ai didi

wpf - AvalonDock 使用默认布局序列化和反序列化时不渲染布局

转载 作者:行者123 更新时间:2023-12-01 09:28:26 26 4
gpt4 key购买 nike

我刚刚开始使用 AvalonDock,几天来我一直在苦苦挣扎。我正在尝试从反序列化的停靠管理器加载我的布局的平凡任务。我尝试了这篇文章所建议的(“AvalonDock DockingManager does not load layout”),但屏幕仍然是空的。

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

非常感谢任何帮助。提前致谢。

最佳答案

我无法 Deserialize 我的布局的原因是我在 LoadLayout 方法中缺少 Serializer.LayoutSerializationCallback 事件。

新的 LoadLayout 方法:

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

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

serializer.Deserialize(DockingLayoutConfig);
}

关于wpf - AvalonDock 使用默认布局序列化和反序列化时不渲染布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19194561/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com