我有一个TabControl允许用户管理以下文档的文件:

在某些时候,我想添加一个功能,允许用户浮动TabItems 并将它们停靠回与TabControl您在 Visual Studio 中可以做的事情差不多的地方。此功能将允许用户更轻松地比较文档并在它们之间复制/粘贴等。
我有一些关于如何去做这件事的一般想法。该TabControl有其ItemsSource必然的文档视图模型的列表。
要浮动选项卡:
Thumb控件添加到TabItem.Thumb,关联的文档视图模型将从TabControl列表中删除。Window被打开,与文档视图模型绑定,以显示/编辑该文档。要停靠选项卡:
DragOver事件处理程序TabControl以识别Window拖过选项卡条区域的文档。TabControl列表中。Window已关闭。有没有关于如何做到这一点的例子,或者你有办法做到这一点?
谢谢。
我一直在使用DockManager和。LayoutRootLayoutAnchorablePaneLayoutDocumentPane
<ad:DockingManager x:Name="dockManager" >
<adLayout:LayoutRoot>
<adLayout:LayoutPanel x:Name="myLayoutPanel" Orientation="Horizontal">
<adLayout:LayoutAnchorablePane x:Name="myLayoutAnchorablePane" DockWidth="400"/>
<adLayout:LayoutDocumentPane x:Name="myDocumentPane" ChildrenCollectionChanged="myDocumentPane_ChildrenCollectionChanged"/>
</adLayout:LayoutPanel>
</adLayout:LayoutRoot>
</ad:DockingManager>
Run Code Online (Sandbox Code Playgroud)
然而,我遇到的一个问题是DockManager.LogicalChildren,当我关闭窗口时,进入 的ContentPresenter和 my永远不会被删除,并且会越来越多,直到它开始减慢应用程序的速度。UserControlLayoutDocumentLogicalChildren
当我检测到 时ChildrenCollectionChanged,如何删除与之关联的ContentPresenter和?UserControlLayoutDocument
编辑1:好的,也是LogicalChildren,System.Linq.Enumerable.WhereSelectListIterator<System.WeakReference,object>所以我无法从该列表中删除任何内容(而且它只有一个get,并且没有set)。
该LayoutDocumentPane.RemoveChild()方法不会对 执行任何操作DockingManager.LogicalChildren,因此我无法弄清楚 是LogicalChildren从哪里提取迭代日期的。
编辑2:所以,我尝试向DocumentClosing事件处理程序添加一个事件DockManager,但它似乎仍然没有LogicalChildren从 DockManager 中删除未使用的事件。
void dockManager_DocumentClosing(object sender, Xceed.Wpf.AvalonDock.DocumentClosingEventArgs e) {
UserControl uc = e.Document.Content as UserControl;
e.Cancel …Run Code Online (Sandbox Code Playgroud) 我熟悉Caliburn Micro及其使用的范例,但我现在正在尝试集成AvalonDock.
作为一个POC,我有一个非常简单的应用程序,其中一个shell视图模型包含一个按钮,用于激活我的StructureViewModels - 一个包含名称和标题的简单类.结构视图是一个用户控件,它只是将名称显示为文本.
ViewModel和Views正在使用Caliburn很好地连接,它们正在Docking Manager中显示.我可以拖动和分离,枚举窗格等 - 所有Avalon功能似乎都有效.我遇到的问题是它们在Avalon标题(标签)中没有标题显示.

ShellViewModel:
using AvalonDemo.Properties;
using Caliburn.Micro;
namespace AvalonDemo.ViewModels
{
public class ShellViewModel : Conductor<IScreen>.Collection.OneActive
{
private int _structureCount;
public ShellViewModel()
{
WindowTitle = Resources.MainWindowTitle;
_structureCount = 1;
}
public string WindowTitle { get; set; }
public void OpenStructure()
{
ActivateItem(new StructureViewModel
{
Name = "Structure" + _structureCount++,
Title = "Structure" + _structureCount
});
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑解决方案:
ShellView:
<Window x:Class="AvalonDemo.Views.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:avalonDock="http://schemas.xceed.com/wpf/xaml/avalondock"
xmlns:cal="http://www.caliburnproject.org"
xmlns:common="clr-namespace:AvalonDemo.Common"
Title="{Binding WindowTitle}"
Height="850" Width="1200">
<Grid>
<Grid.RowDefinitions>
<RowDefinition …Run Code Online (Sandbox Code Playgroud) 我需要在 AvalonDock 2.0 中加载一组项目作为文档。这些对象从一个抽象类继承,我想根据子类在文档中呈现一个框架。
这是我的 XAML:
<ad:DockingManager Background="Gray" DocumentsSource="{Binding Path=OpenProjects}"
ActiveContent="{Binding Path=CurrentProject, Mode=TwoWay}">
<ad:DockingManager.DocumentHeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=OpenProjects/Name}" />
</DataTemplate>
</ad:DockingManager.DocumentHeaderTemplate>
<ad:DockingManager.LayoutItemTemplate>
<DataTemplate>
<Grid>
<Grid.Resources>
<DataTemplate DataType="{x:Type vm:SubclassAViewModel}">
<Frame Source="Pages/SubclassAProject.xaml" />
</DataTemplate>
<DataTemplate DataType="{x:Type vm:SubclassBViewModel}">
<Frame Source="Pages/SubclassBProject.xaml" />
</DataTemplate>
<DataTemplate DataType="{x:Type vm:SubclassCViewModel}">
<Frame Source="Pages/SubclassCProject.xaml" />
</DataTemplate>
</Grid.Resources>
</Grid>
</DataTemplate>
</ad:DockingManager.LayoutItemTemplate>
<ad:LayoutRoot>
<ad:LayoutPanel>
<ad:LayoutDocumentPaneGroup>
<ad:LayoutDocumentPane>
</ad:LayoutDocumentPane>
</ad:LayoutDocumentPaneGroup>
</ad:LayoutPanel>
</ad:LayoutRoot>
</ad:DockingManager>
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经实现了显示与OpenProjects集合中项目一样多的文档,但我似乎无法在每个文档中显示任何内容。
另外,我不知道我ActiveContent是否正确使用:我想分配给CurrentProject当前活动文档上分配的 ViewModel。
感谢您的时间。
与我之前关于使浮动窗口独立于主 DockingManager 的问题相关,这里有一个类似但希望更简单的问题:
AvalonDock 浮动窗口是否可以设置为不位于主 DockingManager 窗口的“Always On Top”?
我正在翻阅AvalonDock 源代码,试图找到一种方法来做到这一点,但我还没有找到任何可行的方法。
理想情况下,我追求的是与 Visual Studio 具有相同效果的东西Tools > Options > Environment > Tabs and Windows > Floating tool windows always stay on top of the main window(至少在 VS2013 和 VS2015 中可用)。
我在我的WPF应用程序中使用Avalon.我想要一个类似于Visual Studio的窗口,左边是Tools,然后是中间的文档和右边的Properties.我设法用这段代码做到了:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock"
xmlns:local="clr-namespace:WpfApplication1"
Title="Window1" Height="600" Width="800">
<Grid>
<ad:DockingManager x:Name="dockManager" RenderTransformOrigin="0,0">
<ad:ResizingPanel Orientation="Vertical">
<ad:ResizingPanel Orientation="Horizontal" >
<ad:DockablePane>
<ad:DockableContent Title="Toolbox" Width="100">
<TextBox />
</ad:DockableContent>
</ad:DockablePane>
<ad:DocumentPane x:Name="documentsHost" OverridesDefaultStyle="True">
<ad:DocumentContent Title="File1.doc">
<RichTextBox/>
</ad:DocumentContent >
<ad:DocumentContent Title="File2.doc">
<RichTextBox/>
</ad:DocumentContent >
</ad:DocumentPane>
<ad:DockablePane>
<ad:DockableContent Title="Project Explorer">
<TextBox />
</ad:DockableContent>
</ad:DockablePane>
</ad:ResizingPanel>
<ad:DockablePane>
<ad:DockableContent Title="Output">
<TextBox />
</ad:DockableContent>
</ad:DockablePane>
</ad:ResizingPanel>
</ad:DockingManager>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
问题是,当我调整其中任何一个时,它们都会调整大小以保持其比例.这不是我想要的,我希望它像VS一样,只是中间的文档窗口调整大小.
我会感激任何帮助,因为我已经与这个斗争了几天了:(
我可以使用WinForms控件,但不能使用整个表单:
var foo = new DockableContent();
foo.Title = "Foo";
foo.Name = "FooName";
var c = new WindowsAppFramework.RenderTargetUserControl();
c.Dock = System.Windows.Forms.DockStyle.Fill;
c.AutomaticUpdateFPS = 60;
var host = new System.Windows.Forms.Integration.WindowsFormsHost();
host.Child = c;
foo.Content = host;
foo.ShowAsDocument(dockManager);
foo.Focus();
Run Code Online (Sandbox Code Playgroud)
是否可以使用整个表格?我想在应用程序中使用现有的表单.
有谁知道如何在AvalonDock 2.0中更改LayoutAnchorable和LayoutDocument标题的字体属性?我希望能够应用我的WPF应用程序中随处使用的样式以保持一致性.
我将ObservableCollection绑定到AvalonDock 2.0,其中集合中的每个项目都是AvalonDock Document.这是我如何进行绑定:
<ad:DockingManager DocumentsSource="{Binding Path=OpenProjects, Mode=TwoWay}" ActiveContent="{Binding Path=CurrentProject, Mode=TwoWay}" LayoutItemTemplateSelector="{StaticResource ProjectTemplateSelector}">
...
</ad:DockingManager>
Run Code Online (Sandbox Code Playgroud)
问题是我想要显示每个项目的名称(在属性Name中指定CurrentProject)作为文档标题.这就是我尝试过的:
<ad:DockingManager.DocumentHeaderTemplate>
<DataTemplate>
<TextBlock DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ad:DockingManager}, Path=ActiveContent, Mode=OneWay}" Text="{Binding Path=Name}" />
</DataTemplate>
</ad:DockingManager.DocumentHeaderTemplate>
Run Code Online (Sandbox Code Playgroud)
如果我只打开一个文档,这可以正常工作,但是当我有几个文档时,它们都会显示Name当前项目.例如,如果我有四个打开的项目,名称为"A","B","C"和"D",如果我当前正在查看文档"C",则所有四个选项卡都将显示标题"C" ",当我改为文件"B"时,他们都将名字改为"B".
有没有办法阻止这种变化?我已经尝试将绑定模式设置为OneTime,但它似乎不起作用.
只有 LayoutDocumentPane 的简单 AvalonDock 应用程序。

XAML:
<Window x:Name="MainWindow1" x:Class="AvalonTest2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
Title="MainWindow" Height="350" Width="525" Loaded="MainWindow1_Loaded">
<Grid Name="MainGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ToolBar Grid.Row="0" Grid.Column="0">
<Button Content="New Tab" Margin="10,0,0,0" Click="NewTabClick"/>
<Button Content="Save layout" Margin="10,0,0,0" Click="Button_Click"/>
</ToolBar>
<xcad:DockingManager x:Name="dockManager" Grid.Row="1">
<xcad:LayoutRoot x:Name="_layoutRoot">
<xcad:LayoutPanel Orientation="Horizontal" x:Name="_layoutPanel">
<xcad:LayoutDocumentPane x:Name="workSpace">
<xcad:LayoutDocument ContentId="dummy" Title="Dummy" >
<Button x:Name="dummyButton" Content="Dummy Content" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</xcad:LayoutDocument>
</xcad:LayoutDocumentPane>
</xcad:LayoutPanel>
</xcad:LayoutRoot>
</xcad:DockingManager>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
代码:
using System;
using System.IO;
using System.Windows;
using Xceed.Wpf.AvalonDock.Layout;
using Xceed.Wpf.AvalonDock.Layout.Serialization;
namespace AvalonTest2 …Run Code Online (Sandbox Code Playgroud)