2013-01-21 29 views
1

我有一個使用Avalon Dock 2.0作爲對接管理器的WPF應用程序。我正面臨Avalon Dock正在執行的新打開標籤的標準定位問題。Avalondock新標籤定位和訂單

只要所有選項卡都適合選項卡欄,新選項卡將被添加到選項卡欄的最右邊位置。只要新選項卡不適合欄,新選項卡將添加到最左邊的位置,使前面最右邊的選項卡消失。

我知道這是Visual Studio的標準行爲,但在我的應用程序中的順序是有意義的。這意味着一個新標籤應始終添加在最左邊或最右邊的位置。該開關對用戶來說非常混亂。

有沒有辦法讓Avalon Dock在最左邊或最右邊的位置上添加一個新標籤?

+0

請問有沒有人有類似的問題? :( –

回答

2

我想通了。我從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; 

    }