无法在WPF应用程序中加载布局

时间:2015-05-22 12:57:45

标签: wpf xml-deserialization

你好我正在使用Windows演示基础,我无法加载我保存的布局,但它没有加载。我使用XmlLayoutSerializer类和
反序列化以加载相应的xml文件。我假设xml文件有问题。你能看看它并检查是否有问题吗?

<?xml version="1.0" encoding="utf-8"?>
<LayoutRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <RootPanel Orientation="Horizontal">
    <LayoutAnchorablePane DockWidth="400">
      <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Selection" IsSelected="True" ContentId="Cont1" CanClose="False" />
      <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Settings" ContentId="Cont2" CanClose="False" />
      <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Security settings" ContentId="Cont3" CanClose="False" />
      <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Log" ContentId="Cont4" CanClose="False" />
    </LayoutAnchorablePane>
    <LayoutDocumentPane>
      <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Project" IsSelected="True" IsLastFocusedDocument="True" ContentId="Cont5" CanClose="False" LastActivationTimeStamp="05/22/2015 14:35:39" />
      <LayoutDocument Title="Layout" ContentId="Cont6" CanClose="False" />
      <LayoutDocument Title="Sequences" ContentId="Cont10" CanClose="False" />
      <LayoutDocument Title="Locations" ContentId="Cont11" CanClose="False" />
      <LayoutDocument Title="Search" ContentId="Cont12" CanClose="False" />
      <LayoutDocument Title="Task generator" ContentId="Cont13" CanClose="False" />
      <LayoutDocument Title="Task manager" ContentId="Cont14" CanClose="False" />
      <LayoutDocument Title="Layout validator" ContentId="Cont15" CanClose="False" />
      <LayoutDocument Title="Variables" ContentId="Cont16" CanClose="False" />
    </LayoutDocumentPane>
    <LayoutAnchorablePane DockWidth="230">
      <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Delta &amp; selection tool" IsSelected="True" ContentId="Cont7" CanClose="False" />
      <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Animations" ContentId="Cont8" CanClose="False" />
      <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Groups" ContentId="Cont9" CanClose="False" />
      <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Zones" ContentId="Cont10" CanClose="False" />
    </LayoutAnchorablePane>
  </RootPanel>
  <TopSide />
  <RightSide />
  <LeftSide />
  <BottomSide />
  <FloatingWindows />
  <Hidden />
</LayoutRoot>

这是我用来保存和加载布局的代码(检查注释//保存布局和//加载布局)。

private void RestoreWindow()
        {
            try
            {
                if (Properties.Settings.Default.WindowHeight == 0 || Properties.Settings.Default.WindowWidth == 0)
                {
                    return;
                }
            }
            catch(Exception e)
            {
                Debugger.Break();
                throw;
            }
            Height = Properties.Settings.Default.WindowHeight;
            Width = Properties.Settings.Default.WindowWidth;
            Left = Properties.Settings.Default.WindowLeft;
            Top = Properties.Settings.Default.WindowTop;
            WindowState = (WindowState)Properties.Settings.Default.WindowState;

            // loading the layout
                using (var reader = new StreamReader("layoutfile.xml"))
            {
               XmlLayoutSerializer layoutSerializer = new XmlLayoutSerializer(DockManager);

                layoutSerializer.Deserialize(reader);
            }                         
        }  

        private void SaveWindow()
        {
            Properties.Settings.Default.WindowWidth = Width;
            Properties.Settings.Default.WindowHeight = Height;
            Properties.Settings.Default.WindowLeft = Left;
            Properties.Settings.Default.WindowTop = Top;
            Properties.Settings.Default.WindowState = (int)WindowState;

            // ensure that your settings are written to the disk
            Properties.Settings.Default.Save();

            // saving the layout
            using (var writer = new StreamWriter("layoutfile.xml"))
            {
                XmlLayoutSerializer layoutSerializer = new XmlLayoutSerializer(DockManager);
                layoutSerializer.Serialize(writer);
            } 

        } 

0 个答案:

没有答案