我在xaml文件中使用avalonDock创建了一个DockingManager,但我想不出一种方法来对齐它在右上角创建的选项卡。它们始终位于左上方。

像这样 :

c# - avalonDock:如何将选项卡与右上角对齐?-LMLPHP

我看过:How to set AvalonDock DockablePane to right in WPF
但我在“ DockingManager”下找不到“ ResizingPanel”

有谁知道该怎么做?

这是我的xaml的示例:

<Grid>
    <avalonDock:DockingManager x:Name="dockingManager"  Margin="0,10,0,-10"
                               DocumentsSource="{Binding Files}"
                               Grid.Row="0" >
        <avalonDock:DockingManager.LayoutItemTemplateSelector>
            <panel:PanelTemplateSelector>
                <panel:PanelTemplateSelector.FileViewTemplate>
                    <DataTemplate>
                        <view:Shooting/>
                    </DataTemplate>
                </panel:PanelTemplateSelector.FileViewTemplate>
            </panel:PanelTemplateSelector>
        </avalonDock:DockingManager.LayoutItemTemplateSelector>


        <avalonDock:DockingManager.LayoutItemContainerStyleSelector>
            <panel:PanelStyleSelector>
                <panel:PanelStyleSelector.StartPageStyle>
                    <Style TargetType="{x:Type avalonControl:LayoutItem}">
                        <Setter Property="Title" Value="{Binding Model.Title}"/>
                        <Setter Property="ToolTip" Value="{Binding Model.StartPageTip}"/>
                        <Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}"/>
                        <Setter Property="IconSource" Value="{Binding Model.IconSource}"/>
                        <Setter Property="ContentId" Value="{Binding Model.ContentId}"/>
                        <Setter Property="CanClose" Value="False"></Setter>
                    </Style>
                </panel:PanelStyleSelector.StartPageStyle>
            </panel:PanelStyleSelector>
        </avalonDock:DockingManager.LayoutItemContainerStyleSelector>

        <avalonDock:DockingManager.LayoutUpdateStrategy>
            <panel:LayoutInitializer/>
        </avalonDock:DockingManager.LayoutUpdateStrategy>

    </avalonDock:DockingManager>

最佳答案

TabItem托管在DocumentPaneTabPanel中,其FlowDirection属性在构造函数中已设置为LeftToRight,

我建议您执行以下操作:


将以下内容复制到DockingManager所在的表单中:

private void DockingManager_LayoutUpdated(object sender, EventArgs e)
{
    var q = FindVisualChild<Xceed.Wpf.AvalonDock.Controls.DocumentPaneTabPanel>(dockingManager);
    if (q != null)
    {
        q.FlowDirection = FlowDirection.RightToLeft;
        dockingManager.LayoutUpdated -= DockingManager_LayoutUpdated;
    }
}
public T FindVisualChild<T>(DependencyObject obj) where T : DependencyObject
{
    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
    {
        DependencyObject child = VisualTreeHelper.GetChild(obj, i);
        if (child != null && child is T)
            return (T)child;
        else
        {
            T childOfChild = FindVisualChild<T>(child);
            if (childOfChild != null)
                return childOfChild;
        }
    }
    return null;
}

在InitializeComponent之后,将以下内容复制到窗体的构造函数中:

  dockingManager.LayoutUpdated += DockingManager_LayoutUpdated;



现在,我的CodeBehind看起来像这样:

    public MainWindow()
    {
        InitializeComponent();
        dockingManager.LayoutUpdated += DockingManager_LayoutUpdated;
    }
    private void DockingManager_LayoutUpdated(object sender, EventArgs e)
    {
        var q = FindVisualChild<Xceed.Wpf.AvalonDock.Controls.DocumentPaneTabPanel>(dockingManager);
        if (q != null)
        {
            q.FlowDirection = FlowDirection.RightToLeft;
            dockingManager.LayoutUpdated -= DockingManager_LayoutUpdated;
        }
    }
    public T FindVisualChild<T>(DependencyObject obj) where T : DependencyObject
    {
        for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
        {
            DependencyObject child = VisualTreeHelper.GetChild(obj, i);
            if (child != null && child is T)
                return (T)child;
            else
            {
                T childOfChild = FindVisualChild<T>(child);
                if (childOfChild != null)
                    return childOfChild;
            }
        }
        return null;
    }

07-27 13:58