【问题标题】:How to fill AvalonDock 2.0 application only with AnchorableWindows - no DocumentPane如何仅使用 AnchorableWindows 填充 AvalonDock 2.0 应用程序 - 无 DocumentPane
【发布时间】:2013-09-04 01:06:27
【问题描述】:

我只想用没有任何文档的“工具”窗口填充 AvalonDock 应用程序。我可以手动最小化文档窗格区域,但如果可能的话,我想用另一个可锚定窗口填充那个小区域,以便 LayoutDocumentPane 的宽度和高度为零。

AvalonDock 框架假设至少有一个空 DocumentPane 的问题在我的例子中变得很明显。即使没有文档,DocumentPane 的空白空间也很容易被它附近的其他工具窗口重叠或重叠。这会使某些窗口部分不可见或填充不足。

到目前为止我的尝试都是徒劳的:

  1. 从 DockManager 声明中删除了 LayoutDocumentPane 标记
  2. 将 LayoutDocumentPane 的 DockWidth 和 DockHeight 设置为零
  3. 手动最小化 DocumentPane 并序列化布局

任何线索将不胜感激

【问题讨论】:

    标签: c# wpf avalondock


    【解决方案1】:

    我在恢复后删除了一个 DocumentPane 的文档:

    public static void Restore(DockingManager dockingManager, string file)
    {
      if (File.Exists(file))
      {
        try
        {
          var serializer = new XmlLayoutSerializer(dockingManager);
    
          // Imparitive for Deserialization
          serializer.LayoutSerializationCallback += (s, args) =>
          {
            args.Content = args.Content;
          };
    
          serializer.Deserialize(file);
    
          var laToDelete = Singleton.WindowMain.DocumentPane.Children
            .OfType<LayoutAnchorable>()
            .ToList();
          for (var index = 0; index < laToDelete.Count; index++)
          {
            LayoutAnchorable layoutAnchorable = laToDelete[index];
            Singleton.WindowMain.DocumentPane.Children.Remove(layoutAnchorable);
          }
        }
        catch
        {
          File.Delete(file);
        }
    
      }
    }
    

    【讨论】:

      【解决方案2】:

      除了更改源代码之外,似乎没有其他办法。在 LayoutRoot.cs 的 CollectGarbage 方法中,我注释掉了以下代码并得到了我想要的 - 没有任何 DocumentPane 的 AvalonDock 应用程序。如果真的没有办法,我强烈建议作者在不修改源的情况下有一个选项。希望它可以帮助像我这样的其他人。

                      if (emptyPane is LayoutDocumentPane &&
                          this.Descendents().OfType<LayoutDocumentPane>().Count(c => c != emptyPane) == 0)
                          continue;
      

      【讨论】:

        【解决方案3】:

        另一种解决方案可以再次加载布局,使用以下代码:

        Dispatcher.Invoke(new Action(() =>
        {
            LoadPageLayout(page);
        }), DispatcherPriority.ContextIdle, null);
        
        private void LoadPageLayout(Dashboard.ViewModel.PageViewModel selectedPage)
        {
            var serializer = new Xceed.Wpf.AvalonDock.Layout.Serialization.XmlLayoutSerialize(dockingManager);
            serializer.LayoutSerializationCallback += (s, args) =>
            {
                args.Content = args.Content;
            };
        
            var layoutToRestore = selectedPage.GetLayout();
            if (!String.IsNullOrEmpty(layoutToRestore))
            {
                // Remove any existing LayoutDocumentPane
                var cleanedLayout = RemoveAllEmptyXmlNodes(layoutToRestore);
        
                StringReader textReader = new StringReader(cleanedLayout);
                serializer.Deserialize(textReader);
            }
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-11-29
          • 1970-01-01
          相关资源
          最近更新 更多