2011-05-25 72 views
1

如何使標籤項標題在Silverlight中的標籤控件寬度上展開?如果它很重要,我總是有一個固定數量的選項卡。Silverlight中的Strech TabItem標頭

我發現只是WPF的例子,與IMultiValueConverter here

+0

編碼風格意味着寫入代碼的風格。它不會影響UI的風格。請參閱[本說明](http://en.wikipedia.org/wiki/Programming_style)。 – 2011-05-25 11:11:45

回答

2

下面的例子

http://cid-a1de71e9f2ae2f82.office.live.com/self.aspx/.Public/ExtendedTabControl.zip

這preaty簡單的任務。所有你所要做的就是創建默認模板的複製與te:StockPanel x:Name="TabPanelTop"這basicly覆蓋佈局邏輯取代System_Windows_Controls_Primitives:TabPanel x:Name="TabPanelTop" ..

public class StockPanel: System.Windows.Controls.Primitives.TabPanel 
{ 
    protected override Size MeasureOverride(Size availableSize) 
    { 
     var cc = Children.Count; 

     foreach (var child in Children) 
     { 
      child.Measure(new Size(availableSize.Width/cc, availableSize.Height)); 
     } 

     return base.MeasureOverride(availableSize); 
    } 

    protected override Size ArrangeOverride(Size finalSize) 
    { 
     var cc = Children.Count; 
     var i = 0; 

     foreach (var child in Children) 
     { 
      child.Arrange(new Rect((finalSize.Width/cc) * i, 0, finalSize.Width/cc, finalSize.Height)); 
      i++; 
     } 

     return new Size(finalSize.Width, finalSize.Height); 
    } 
} 

PS:這不是完美的代碼示例,但我認爲它是enouth爲您瞭解如何擴展TabControl

+0

謝謝,但我無法下載你的代碼。請給我發電子郵件! – Aaaaaaaa 2011-05-25 12:28:59

+0

試試這個http://cid-a1de71e9f2ae2f82.office.live.com/self.aspx/.Public/ExtendedTabControl.zip – 2011-05-25 12:37:30