Wpf Avalondock新标签定位和订单

Wpf Avalondock新标签定位和订单,wpf,avalondock,Wpf,Avalondock,我有一个使用Avalon Dock 2.0作为停靠管理器的WPF应用程序。我面临一个问题,关于阿瓦隆船坞正在执行的新打开标签的标准定位 只要所有选项卡都适合选项卡栏,就会在选项卡栏的最右侧位置追加一个新选项卡。一旦新选项卡不适合该栏,新选项卡将添加到最左侧的位置,从而显示以前最右侧的选项卡 我知道这是VisualStudio的标准行为,但在我的应用程序中,顺序有其意义。这意味着新选项卡应始终添加在最左侧或最右侧的位置。这个开关让用户很困惑 有没有办法让Avalon Dock始终在最左边或最右边添

我有一个使用Avalon Dock 2.0作为停靠管理器的WPF应用程序。我面临一个问题,关于阿瓦隆船坞正在执行的新打开标签的标准定位

只要所有选项卡都适合选项卡栏,就会在选项卡栏的最右侧位置追加一个新选项卡。一旦新选项卡不适合该栏,新选项卡将添加到最左侧的位置,从而显示以前最右侧的选项卡

我知道这是VisualStudio的标准行为,但在我的应用程序中,顺序有其意义。这意味着新选项卡应始终添加在最左侧或最右侧的位置。这个开关让用户很困惑


有没有办法让Avalon Dock始终在最左边或最右边添加一个新选项卡?

我想出来了。我从DocumentPaneTabPanel更改了ArrangeOverride(Size finalSize)方法中的代码,以防止将当前选项卡重新定位到第一个位置

现在它会隐藏当前面板左侧不适合面板的选项卡-首先隐藏最左侧的选项卡。当前选项卡右侧的选项卡也被隐藏-此处最右侧的选项卡首先被隐藏。如果出现溢出,则当前选项卡始终位于面板的最右侧。目前这有点脏,但我认为以更好的方式实现这一点应该没有那么难

代码如下:

    protected override Size ArrangeOverride(Size finalSize)
    {
        double offset = 0.0;
        var children = Children.Cast<UIElement>().Where(ch => ch.Visibility != System.Windows.Visibility.Collapsed).ToList();
        if (children.Count > 0)
        {
            //find currently selected tab
            int i = 0;
            for (i = 0; i < children.Count(); i++)
            {
                TabItem doc = (TabItem)children[i];
                var layoutContent = doc.Content as LayoutContent;
                if (layoutContent.IsSelected)
                    break;
            }

            //calculate how many tabs left from the currently selected would fit in the panel
            int cur_ind = i;
            TabItem current_item = (TabItem)children[cur_ind];
            List<TabItem> t_to_display = new List<TabItem>();
            while (cur_ind >= 0 && offset + current_item.DesiredSize.Width <= finalSize.Width)
            {
                current_item = (TabItem)children[cur_ind];
                current_item.Visibility = System.Windows.Visibility.Visible;
                offset += current_item.DesiredSize.Width + current_item.Margin.Left + current_item.Margin.Right;
                t_to_display.Add(current_item);
                --cur_ind;
            }

            //arrange the fitting tabs on the left
            double cur_offset = offset;
            foreach (TabItem t in t_to_display)
            {
                cur_offset -= t.DesiredSize.Width + t.Margin.Left + t.Margin.Right;
                t.Arrange(new Rect(cur_offset, 0.0, t.DesiredSize.Width, finalSize.Height));
            }

            //arrange the tabs on the right
            cur_ind = i + 1;
            while (cur_ind < children.Count && offset + current_item.DesiredSize.Width <= finalSize.Width)
            {
                current_item = (TabItem)children[cur_ind];
                current_item.Visibility = System.Windows.Visibility.Visible;
                current_item.Arrange(new Rect(offset, 0.0, current_item.DesiredSize.Width, finalSize.Height));
                offset += current_item.DesiredSize.Width + current_item.Margin.Left + current_item.Margin.Right;
                cur_ind++;
            }

            while(cur_ind < children.Count)
            {
                current_item = (TabItem)children[cur_ind];
                current_item.Visibility = System.Windows.Visibility.Hidden;
                cur_ind++;
            }
        }

        return finalSize;

    }
受保护的替代大小排列替代(大小最终化)
{
双偏移=0.0;
var children=children.Cast().Where(ch=>ch.Visibility!=System.Windows.Visibility.collazed.ToList();
如果(children.Count>0)
{
//查找当前选定的选项卡
int i=0;
对于(i=0;i当(cur_ind>=0&&offset+current_item.DesiredSize.Width时,我找到了它。我从DocumentPaneTabPanel更改了ArrangeOverride(Size finalSize)方法中的代码,以防止当前选项卡重新定位到第一个位置

它现在隐藏了当前选项卡左侧与面板不匹配的选项卡-首先隐藏最左侧的选项卡。当前选项卡右侧的选项卡也被隐藏-这里最右侧的选项卡首先被隐藏。如果出现溢出,则当前选项卡始终是面板上最右侧的选项卡。目前这有点脏,但我认为用更好的方式来做这件事不应该那么难

代码如下:

    protected override Size ArrangeOverride(Size finalSize)
    {
        double offset = 0.0;
        var children = Children.Cast<UIElement>().Where(ch => ch.Visibility != System.Windows.Visibility.Collapsed).ToList();
        if (children.Count > 0)
        {
            //find currently selected tab
            int i = 0;
            for (i = 0; i < children.Count(); i++)
            {
                TabItem doc = (TabItem)children[i];
                var layoutContent = doc.Content as LayoutContent;
                if (layoutContent.IsSelected)
                    break;
            }

            //calculate how many tabs left from the currently selected would fit in the panel
            int cur_ind = i;
            TabItem current_item = (TabItem)children[cur_ind];
            List<TabItem> t_to_display = new List<TabItem>();
            while (cur_ind >= 0 && offset + current_item.DesiredSize.Width <= finalSize.Width)
            {
                current_item = (TabItem)children[cur_ind];
                current_item.Visibility = System.Windows.Visibility.Visible;
                offset += current_item.DesiredSize.Width + current_item.Margin.Left + current_item.Margin.Right;
                t_to_display.Add(current_item);
                --cur_ind;
            }

            //arrange the fitting tabs on the left
            double cur_offset = offset;
            foreach (TabItem t in t_to_display)
            {
                cur_offset -= t.DesiredSize.Width + t.Margin.Left + t.Margin.Right;
                t.Arrange(new Rect(cur_offset, 0.0, t.DesiredSize.Width, finalSize.Height));
            }

            //arrange the tabs on the right
            cur_ind = i + 1;
            while (cur_ind < children.Count && offset + current_item.DesiredSize.Width <= finalSize.Width)
            {
                current_item = (TabItem)children[cur_ind];
                current_item.Visibility = System.Windows.Visibility.Visible;
                current_item.Arrange(new Rect(offset, 0.0, current_item.DesiredSize.Width, finalSize.Height));
                offset += current_item.DesiredSize.Width + current_item.Margin.Left + current_item.Margin.Right;
                cur_ind++;
            }

            while(cur_ind < children.Count)
            {
                current_item = (TabItem)children[cur_ind];
                current_item.Visibility = System.Windows.Visibility.Hidden;
                cur_ind++;
            }
        }

        return finalSize;

    }
受保护的替代大小排列替代(大小最终化)
{
双偏移=0.0;
var children=children.Cast().Where(ch=>ch.Visibility!=System.Windows.Visibility.collazed.ToList();
如果(children.Count>0)
{
//查找当前选定的选项卡
int i=0;
对于(i=0;i而(cur_ind>=0&&offset+current_item.DesiredSize.Width)是否没有人有类似的问题?:(是否没有人有类似的问题?:(