avalonDock:如何将标签对齐到右上角?

时间:2016-05-25 09:42:07

标签: c# wpf xaml avalondock

我正在我的xaml文件中创建一个带有avalonDock的DockingManager,我无法找到一种方法来对齐它在右上角创建的标签。他们总是在左上角。

像这样:

enter image description here

我见过:How to set AvalonDock DockablePane to right in WPF 但我找不到“Doc​​kingManager”下的“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>

1 个答案:

答案 0 :(得分:0)

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

我建议您执行以下操作:

  1. 在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;
    }
    
  2. 在InitializeComponent之后在表单的构造函数中复制以下内容:

      dockingManager.LayoutUpdated += DockingManager_LayoutUpdated;
    
  3. 现在,我的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;
        }